<?php
class ActivityService extends AbstractService {
    const ActivityShare             = 2;  // 分享活动
    const ActivityInvite            = 6;  // 分享邀请好友活动
    const ActivityJump              = 7;  // 中秋跳跃活动
    const ActivitySynthesis         = 8;  // 万圣节合成活动
    const ActivityFirstPay          = 9;  // 首充
    const ActivityLottery           = 10; // 转盘抽奖
    const ActivityChristmas         = 11; // 圣诞树
    const ActivityPay               = 12; // 充值活动
    const ActivityTree              = 13; // 春节树活动
    const ActivityValentine         = 14; // 情人节活动
    const ActivityValentine1        = 15; // 女王节活动
    const ActivityPersonalGoals     = 16; // 个人目标活动
    const ActivityChildren          = 17;  //儿童节活动
    const PrivateKey                = 'a4FgAs1d7Sg8Ndfs6c2def5360dd26';

    /**
     * @var ActivityService
     */
    private static $instance;

    /**
     * Get the instance of ActivityService.
     *
     * @return ActivityService
     */
    public static function get() {
        if (!self::$instance) {
            self::$instance = new ActivityService();
        }
        return self::$instance;
    }

    /**
     * Construction.
     */
    protected function __construct() {
        parent::__construct();
    }

    /**
     * 处理用户创建时的逻辑
     *
     * @param int $shardId
     * @return void
     */
    public function handleCreate($shardId) {

    }

    /**
     * 处理用户登录时的逻辑
     *
     * @param int $userId
     * @return void
     */
    public function handleLogin($userId) {
        ActivityService::get()->flush($userId);
    }

    /**
     * 处理 service 对外提供的全量数据
     *
     * @param int $userId
     * @return array
     */
    public function info($userId) {
        return $this->getActivityInfo();
    }

    /**
     * 获得活动信息
     * @return array
     */
    private function getActivityInfo () {
        $activitySettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, null, true);
        $data = array();
        $eventInviteId = 0;
        if ($activitySettings) {
            $serverTime = GameService::get()->getReqTime();
            foreach ($activitySettings as $activityId=>$activity) {
                $startTime = $activity['startTime'];
                if ($startTime > $serverTime) {
                    continue;
                }
                $endTime = $activity['endTime'];
                if ($endTime <= $serverTime) {
                    continue;
                }
                $data[$activityId] = $activity;
                if ($activity['type'] == 6 && !$eventInviteId) {
                    $eventInviteId = $activityId;
                }
            }
        }
        return array($data,$eventInviteId);
    }

    /**
     * 七夕分享活动信息
     * @param $userId
     * @param $activityId
     * @return array
     * @throws SzException
     */
    public function getShareInfo($userId,$activityId) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $serverTime = GameService::get()->getReqTime();
        $startTime = $activity['startTime'];
        if ($startTime > $serverTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $serverTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityShare) {
            throw new SzException(90005);
        }

        /**
         * @var $userActivityShare ActivityShareVo
         */
        $userActivityShareList = SzPersister::get()->getVoList($activityId.$userId, GameConst::ORM_NAME_ACTIVITY_SHARE);
        if (!$userActivityShareList->toArray()) {
            return array('info' => array());
        }
        $data = array();
        $userActivityShareLists = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SHARE);
        $userActivityShare = $userActivityShareLists->getElement($activityId,false);
        $status = 0;
        if ($userActivityShare) {
            $status = 1;
        }
        foreach ($userActivityShareList->toArray() as $val) {
            $profileInfoList = SzPersister::get()->getVoList($val['friendId'], ModuleProfileConst::ORM_NAME_PROFILE_INFO);
            $data[$val['position']] = array(
                'position' => $val['position'],
                'userId' => $val['friendId'],
                'userLevel' => UserService::get()->getUserLevel($val['friendId']),
                'townName' => UserService::get()->getTownName($val['friendId'], $profileInfoList),
                'headImgId' => UserService::get()->getHeadIcon($val['friendId'], $profileInfoList),
                'isAward' => $val['isAward']
            );

            $profileInfo = $profileInfoList->getElement(GameConst::USER_INFO_TYPE_HEAD_FRAME,false);
            if (!$profileInfo){
                $data[$val['position']]['headFrame'] = 0;
            }
            else{
                $data[$val['position']]['headFrame'] = $profileInfo->getInfo();
            }

        }
        return array(
            'status' => $status,
            'info' => $data
        );
    }

    /**
     * 七夕活动删除位置好友
     * @param $userId
     * @param $position
     * @param $friendId
     * @param $activityId
     * @throws SzException
     */
    public function deleteFriend($userId,$friendId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityShare) {
            throw new SzException(90005);
        }

        /**
         * @var $userActivityShare ActivityShareVo
         */
        $userActivityShareList = SzPersister::get()->getVoList($activityId.$userId, GameConst::ORM_NAME_ACTIVITY_SHARE);
        $userActivityShare = $userActivityShareList->getElement($friendId);
        if ($userActivityShare->getIsAward()) {
            throw new SzException(90004);
        }
        $position = $userActivityShare->getPosition();
        $userActivityShareList->deleteElement($friendId);
        SzPersister::get()->setVoList($userActivityShareList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:kick|',
                'item' => $friendId.'&'.$position,
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 七夕活动位置领奖
     * @param $userId
     * @param $position
     * @param $friendId
     * @param $activityId
     * @return bool|void
     * @throws SzException
     */
    public function rewardFriend($userId,$friendId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        if ($activity['type'] != self::ActivityShare) {
            throw new SzException(90005);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        $inviteEventSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_INVITE_EVENT, $activityId, true);

        /**
         * @var ModuleProfileVo $profile
         */
        $profile = SzPersister::get()->getVo($friendId, ModuleProfileConst::ORM_NAME_PROFILE);
        $activity['param'] = json_decode($activity['parms'],true);
        if ($profile->getLevel() < $activity['param']['lv']) {
            throw new SzException(90006);
        }

        /**
         * @var $userActivityShare ActivityShareVo
         */
        $userActivityShareList = SzPersister::get()->getVoList($activityId.$userId, GameConst::ORM_NAME_ACTIVITY_SHARE);
        $userActivityShare = $userActivityShareList->getElement($friendId);
        if ($userActivityShare->getIsAward()) {
            throw new SzException(90007);
        }
        $position = $userActivityShare->getPosition();
        $reward = $inviteEventSetting['award_'.$position][0];
        $output = '';
        foreach ($reward as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_SHARE,$userId,1,$output,'rewardFriend');//获得资源上报

        $userActivityShare->setIsAward(1);
        $userActivityShareList->updateElement($friendId,$userActivityShare);
        SzPersister::get()->setVoList($userActivityShareList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:success|',
                'item' => $friendId.'&'.$position,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' => $output,
                'item' => 'valentine&'.$friendId.'&'.$position,
            )
        ));

        return true;
    }

    /**
     * 七夕活动大奖领取
     * @param $userId
     * @param $activityId
     * @return bool
     * @throws SzException
     */
    public function reward($userId,$activityId,$reqTime) {
        $userActivityShareList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SHARE);
        $userActivityShare = $userActivityShareList->getElement($activityId,false);
        if($userActivityShare) {
            throw new SzException(90007);
        }

        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        if ($activity['type'] != self::ActivityShare) {
            throw new SzException(90005);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        $inviteEventSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_INVITE_EVENT, $activityId, true);

        /**
         * @var $userActivityShare ActivityShareVo
         */
        $userActivityShareLists = SzPersister::get()->getVoList($activityId.$userId, GameConst::ORM_NAME_ACTIVITY_SHARE);
        if (count($userActivityShareLists->getList()) < $inviteEventSetting['position']) {
            throw new SzException(90003);
        }

        foreach ($userActivityShareLists->toArray() as $userActivityShare) {
            if (!$userActivityShare['isAward']) {
                throw new SzException(90003);
            }
        }

        $reward = $inviteEventSetting['award_0'];
        $output = '';
        foreach ($reward as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_SHARE,$userId,1,$output,'reward');//获得资源上报

        $userActivityShare = new ActivityShareVo($userId,$activityId,0,1,true);
        $userActivityShareList->addElement($userActivityShare);
        $userActivityShareList->setElement($activityId,$userActivityShare);
        SzPersister::get()->setVoList($userActivityShareList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:achieve|',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' => $output,
                'item' => 'valentine&achieve',
            )
        ));

        return true;
    }

    /**
     * 刷新活动
     * @param int $userId
     * @param int $indexId
     * @param int $reqTime
     * @param int $level
     * @return void
     * @throws SzException
     */
    public function flush($userId, $indexId = null, $reqTime = null, $level = null)
    {
        $activitySettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $indexId, true);
        if (!is_null($indexId)) {
            $activitySettings = [$indexId => $activitySettings];
        }
        $reqTime = is_null($reqTime) ? GameService::get()->getReqTime() : $reqTime;
        $level = is_null($level) ? UserService::get()->getUserLevel($userId) : $level;
        foreach ($activitySettings as $_indexId => $activity) {
            if ($level < $activity['triggerLv']) {//等级未达到
                continue;
            }
            $startTime = $activity['startTime'];
            if ($startTime > $reqTime) {//活动未开启
                continue;
            }
            switch ($activity['type']) {
                case GameConst::ACTIVITY_TYPE_SEVEN_EVENT:
                    ActivitySevenEventService::get()->flush($userId, $_indexId, $activity['endTime'], $reqTime);
                    break;
                case GameConst::ACTIVITY_TYPE_DAILY_LOGIN:
                    ActivityDailyLoginService::get()->flush($userId, $_indexId, $activity['endTime'], $reqTime);
                    break;
            }
        }
    }

    /**
     * 新手邀请活动信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function getInviteInfo($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT_INVITE, $activityId, true);

        if ($activity['type'] != self::ActivityInvite) {
            throw new SzException(90005);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }
        $result = array();
        /**
         * @var $friendList NewFriendsVoList
         * @var $friend NewFriendsVo
         * @var $eventInviteList EventInviteVoList
         */
        $friendList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_NEW_FRIEND);
        if (!$friendList) {
            return array(
                'list' => $result,
            );
        }
        $inviteCount = 0;
        foreach ($friendList->getList() as $friendUserId => $friend) {
            if ($friend->getInviteId() == $activityInfo['inviteId']) {
                $inviteCount++;
                $profileInfoList = SzPersister::get()->getVoList($friendUserId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);
                $temp = array(
                    'userId' => $friendUserId,
                    'userLevel' => UserService::get()->getUserLevel($friendUserId),
                    'townName' => UserService::get()->getTownName($friendUserId, $profileInfoList),
                    'headImgId' => UserService::get()->getHeadIcon($friendUserId, $profileInfoList),
                    'gender' => UserService::get()->getGender($friendUserId,$profileInfoList),
                );

                //获取玩家的头像框数据
                $profileInfo = $profileInfoList->getElement(GameConst::USER_INFO_TYPE_HEAD_FRAME,false);
                if (!$profileInfo){
                    $temp['headFrame'] = 0;
                }
                else{
                    $temp['headFrame'] = $profileInfo->getInfo();
                }
                $result[] = $temp;

                if ($inviteCount >= $activityInfo['inviteNum']) {
                    break;
                }
            }
        }

        return array(
            'list' => $result,
        );
    }

    /**
     * 新手邀请活动领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function getInviteReward($userId,$activityId,$indexId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT_INVITE, $activityId, true);

        if ($activity['type'] != self::ActivityInvite) {
            throw new SzException(90005);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        $eventInviteList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_EVENT_INVITE);

        if ($indexId) {
            $diamondSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_DIAMOND_VALUE, $indexId, true);
            // 扣除钻石
            GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_CONSUME_MONEY, $diamondSetting['price'], true);
            CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_INVITE,$userId,0,GameConst::ENTITY_ACTION_CONSUME_MONEY.':'.$diamondSetting['price'].'|','getInviteReward');//消耗资源上报
        } else {
            /**
             * @var $friendList NewFriendsVoList
             * @var $friend NewFriendsVo
             * @var $eventInviteList EventInviteVoList
             */
            if ($eventInviteList->getElement($activityId,false)) {
                throw new SzException(90007);
            }
            $friendList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_NEW_FRIEND);
            if (!$friendList) {
                return false;
            }

            $inviteCount = 0;
            foreach ($friendList->getList() as $friendUserId => $friend) {
                if ($friend->getInviteId() == $activityInfo['inviteId']) {
                    $inviteCount++;
                    if ($inviteCount >= $activityInfo['inviteNum']) {
                        break;
                    }
                }
            }

            if ($inviteCount < $activityInfo['inviteNum']) {
                throw new SzException(90008);
            }
        }

        $output = '';
        foreach ($activityInfo['reward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_INVITE,$userId,1,$output,'getInviteReward');//获得资源上报

        $eventInvite = new EventInviteVo($userId,$activityId,$reqTime,true);
        $eventInviteList->addElement($eventInvite);
        $eventInviteList->setElement($activityId,$eventInvite);
        SzPersister::get()->setVoList($eventInviteList);

        if ($indexId) {
            // 数据采集:行为
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                'clientData' => array(
                    'tid' => 'Module:cash|action:exchange|',
                    'item' => $indexId,
                    'value' => 1
                )
            ));

            // 数据采集
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'cash&exchange&' . $indexId,
                    'value' => $diamondSetting['price']
                )
            ));

            // 数据采集
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' => $output,
                    'item' => 'cash&exchange&' . $indexId,
                )
            ));
        } else {
            // 数据采集
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                'clientData' => array(
                    'tid' => 'Module:new_gift|action:achieve|',
                    'value' => 1
                )
            ));

            // 数据采集
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' =>$output,
                    'item' => 'new_gift&achieve'
                )
            ));
        }

        return true;
    }

    /**
     * 中秋跳跃活动信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityJumpInfo($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);
        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        /**
         * @var $activityJumpList ActivityJumpVoList
         * @var $activityJump ActivityJumpVo
         */
        $activityJumpList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_JUMP);
        $activityJump = $activityJumpList->getElement($activityId,false);
        $data = array();
        if ($activityJump) {
            $data = $activityJump->toArray();
        }

        return $data;
    }

    /**
     * 消耗次数玩游戏
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityJumpPlay($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        /**
         * @var $activityJumpList ActivityJumpVoList
         * @var $activityJump ActivityJumpVo
         */
        $activityJumpList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_JUMP);
        $activityJump = $activityJumpList->getElement($activityId,false);
        if (!$activityJump) {
            $activityJump = new ActivityJumpVo($userId,$activityId,0,0,0,0,0,0,array(),true);
        }

        // 次日刷新
        if (SzTime::getDate($reqTime) != SzTime::getDate($activityJump->getFreeRefreshTime())) {
            if ($activityJump->getFreeTime() < $activityInfo['defaultNum']) {
                $activityJump->setFreeTime($activityInfo['defaultNum']);
            }
            $activityJump->setFreeRefreshTime($reqTime);
            $activityJump->setVideoTimes(0);
        }
        
        $num = VideoService::get()->getActivityJumpNum($userId,$reqTime);
        $videoNum = $activityJump->getVideoTimes();
        if ($num && $num > $videoNum) {
            $activityJump->setFreeTime(($activityJump->getFreeTime() + $num - $videoNum));
            $activityJump->setVideoTimes($num);
        }

        if ($activityJump->getFreeTime() < 1) {
            throw new SzException(90052);
        }

        $activityJump->setGameState(1);
        $activityJump->updateFreeTime(1);
        $reward = array();
        list($min,$max) = $activityInfo['everyAward'];
        for($i = 0;$i < 2;$i++) {
            $itemId = mt_rand(0,($max-$min)) + $min;
            $itemId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_GET, GameConst::ENTITY_TYPE_ITEM, $itemId);
            $reward[$itemId] += 1;
        }
        $activityJump->setReward($reward);

        if ($activityJump->isInsert() && !SzUtility::checkArrayKey($activityId, $activityJumpList->getList())) {
            $activityJumpList->addElement($activityJump);
            $activityJumpList->setElement($activityId,$activityJump);
        } else {
            $activityJumpList->updateElement($activityId,$activityJump);
        }
        SzPersister::get()->setVoList($activityJumpList);


        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:rabbit|action:start|',
                'item' => 'lift&'.$activityJump->getFreeTime(),
                'value' => 1
            )
        ));

        return $reward;
    }

    /**
     * 复活
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityJumpRevive($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        $num = 0;
        $output = '';
        foreach ($activityInfo['resurgence'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $num = $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_INVITE,$userId,0,$output,'activityJumpRevive');//消耗资源上报

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:rabbit|action:end|',
                'item' => 'revive',
                'value' => 1
            )
        ));

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
            'clientData' => array(
                'item' => 'rabbit_end&revive',
                'value' => $num
            )
        ));

        return true;
    }

    /**
     * 完成后结算
     * @param $userId
     * @param $activityId
     * @param $score
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityJumpScore($userId,$activityId,$score,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        /**
         * @var $activityJumpList ActivityJumpVoList
         * @var $activityJump ActivityJumpVo
         */
        $activityJumpList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_JUMP);
        $activityJump = $activityJumpList->getElement($activityId);

        if ($activityJump->getGameState() != 1) {
            throw new SzException(90053);
        }
        $output = '';
        if ($score >= $activityInfo['everyScore']) {
            foreach ($activityJump->getRawReward() as $entityId => $count) {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
                $output .= $entityId.':'.$count.'|';
            }
        }

        $activityJump->setGameState(2);
        if ($activityJump->getScore() < $score) {
            $activityJump->setScore($score);
        }

        $activityJumpList->updateElement($activityId,$activityJump);
        SzPersister::get()->setVoList($activityJumpList);

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:rabbit|action:end|',
                'item' => 'score&'.$score,
                'value' => 1
            )
        ));

        if ($output) {
            CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_INVITE,$userId,1,$output,'activityJumpScore');//获得资源上报
            // 数据采集
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' =>$output,
                    'item' => 'rabbit_end'
                )
            ));
        }

        return true;
    }

    /**
     * 排行榜信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityJumpRank($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        $data = array();
        /**
         * @var $activityJumpList ActivityJumpVoList
         * @var $activityJump ActivityJumpVo
         */
        $activityJumpList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_JUMP);
        $activityJump = $activityJumpList->getElement($activityId,false);
        if ($activityJump) {
            $data[] = $this->getUserInfo($userId,$activityJump->getScore());
        }
        $friendList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_NEW_FRIEND);
        if ($friendList) {
            foreach ($friendList->toArray() as $friendId=>$v) {
                $activityJumpList = SzPersister::get()->getVoList($friendId, GameConst::ORM_NAME_ACTIVITY_JUMP);
                $activityJump = $activityJumpList->getElement($activityId,false);
                if ($activityJump) {
                    $data[] = $this->getUserInfo($friendId,$activityJump->getScore());
                }
            }
        }
        return $data;
    }

    /**
     * 排行榜领奖
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityJumpReward($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);

        $startTime = $activity['parms'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        /**
         * @var $activityJumpList ActivityJumpVoList
         * @var $activityJump ActivityJumpVo
         */
        $activityJumpList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_JUMP);
        $activityJump = $activityJumpList->getElement($activityId);

        if ($activityJump->getStatus()) {
            throw new SzException(90007);
        }

        $score = $activityJump->getScore();

        $index = null;
        foreach ($activityInfo['rabbitScore'] as $k=>$v) {
            if ($v > $score) {
                break;
            } else if ($v <= $score) {
                $index = $k;
            }
        }

        if (is_null($index)) {
            throw new SzException(90054);
        }

        $reward = $activityInfo['rabbitAward'];
        $output = '';
        foreach ($reward[$index] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_INVITE,$userId,1,$output,'activityJumpReward');//获得资源上报

        $activityJump->setStatus(1);
        $activityJumpList->updateElement($activityId,$activityJump);
        SzPersister::get()->setVoList($activityJumpList);

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:rabbit|action:rank|',
                'item' => 'rank',
                'value' => 1
            )
        ));

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'rabbit_rank'
            )
        ));

        return true;
    }

    /**
     * 购买次数
     * @param $userId
     * @param $activityId
     * @param $num
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityJumpBuyFreeTime($userId,$activityId,$num,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $activityInfo = SzConfig::get()->loadAppConfig(GameConst::CONFIG_RABBIT_JUMP, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityJump) {
            throw new SzException(90005);
        }

        /**
         * @var $activityJumpList ActivityJumpVoList
         * @var $activityJump ActivityJumpVo
         */
        $activityJumpList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_JUMP);
        $activityJump = $activityJumpList->getElement($activityId,false);
        if (!$activityJump) {
            $activityJump = new ActivityJumpVo($userId,$activityId,0,0,0,0,0,0,array(),true);
        }

        // 次日刷新
        if (SzTime::getDate($reqTime) != SzTime::getDate($activityJump->getFreeRefreshTime())) {
            if ($activityJump->getFreeTime() < $activityInfo['defaultNum']) {
                $activityJump->setFreeTime($activityInfo['defaultNum']);
            }
            $activityJump->setFreeRefreshTime($reqTime);
            $activityJump->setVideoTimes(0);
        }

        $rabbitBuy = SzConfig::get()->loadAppConfig(ModuleProfileConst::CONFIG_PROFILE, 'rabbitBuy', true);
        $rabbitBuy = $rabbitBuy['value'];
        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_CONSUME_MONEY, ($rabbitBuy * $num), true);
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_ACTIVITY_INVITE,$userId,0,GameConst::ENTITY_ACTION_CONSUME_MONEY.':'.($rabbitBuy * $num).'|','activityJumpBuyFreeTime');//消耗资源上报

        $activityJump->updateFreeTime(-$num);

        if ($activityJump->isInsert() && !SzUtility::checkArrayKey($activityId, $activityJumpList->getList())) {
            $activityJumpList->addElement($activityJump);
            $activityJumpList->setElement($activityId,$activityJump);
        } else {
            $activityJumpList->updateElement($activityId,$activityJump);
        }
        SzPersister::get()->setVoList($activityJumpList);

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:rabbit|action:end|',
                'item' => 'revive',
                'value' => 1
            )
        ));

        // 数据采集
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
            'clientData' => array(
                'item' => 'rabbit_end&revive',
                'value' => ($rabbitBuy*$num)
            )
        ));

        return $activityJump->getFreeTime();
    }



    /***********************************万圣节合成活动*********************************************/
    /**
     * 万圣节活动信息
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activitySynthesisInfo($userId,$activityId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

    /*    $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }
        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        /**
         * @var $activitySynthesisBoxList ActivitySynthesisBoxVoList
         * @var $activitySynthesisBox ActivitySynthesisBoxVo
         * @var $activitySynthesisList ActivitySynthesisVoList
         * @var $activitySynthesis ActivitySynthesisVo
         */
        $activitySynthesisBoxList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS_BOX);
        $activitySynthesisBoxSettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_SYNTHESIS_BOX,null, true);
        $isInsert = false;
        $info = array();
        foreach ($activitySynthesisBoxSettings as $activitySynthesisBoxSetting) {
            if ($activityId != $activitySynthesisBoxSetting['activityId']) {
                continue;
            }
            if (!$activitySynthesisBoxSetting['isFree']) {
                continue;
            }
            $activitySynthesisBox = $activitySynthesisBoxList->getElement($activityId.'_'.$activitySynthesisBoxSetting['position'],false);
            if (!$activitySynthesisBox) {
                $isInsert = true;
                $activitySynthesisBox = new ActivitySynthesisBoxVo($userId,$activityId.'_'.$activitySynthesisBoxSetting['position'],0,0,true);
                $activitySynthesisBoxList->addElement($activitySynthesisBox);
                $activitySynthesisBoxList->setElement($activityId.'_'.$activitySynthesisBoxSetting['position'],$activitySynthesisBox);
            }
        }
        if ($isInsert) {
            SzPersister::get()->setVoList($activitySynthesisBoxList);
        }

        $activityMakeHoneyList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_MAKE_HONEY);
        $activityMakeHoney = $activityMakeHoneyList->getElement($activityId, false);
        $data = array();
        if ($activityMakeHoney) {
            $data = $activityMakeHoney->toArray();
        }
        $activitySynthesisList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS);
        $activitySynthesis = $activitySynthesisList->getElement($activityId,false);
        $status = 0;
        $num = 0;
        if ($activitySynthesis) {
            $status = $activitySynthesis->getStatus();
            $num = $activitySynthesis->getNumber();
        }

        $rankList = array();
        if ($activity['type'] == self::ActivitySynthesis) {
            $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
            $rankList = $redisDb->zRevRange(GameConst::CACHE_KEY_ACTIVITY_SYNTHESIS_RANK.$activityId,0,99,true);
        }

        $myRank = $rank = 0;

        if ($rankList) {
            foreach ($rankList as $uId=>$number) {
                $rank++;
                if ($userId == $uId) {
                    $myRank = $rank;
                    break;
                }
            }
        }

        if ($activitySynthesisBoxList->toArray()) {
            foreach ($activitySynthesisBoxList->toArray() as $k=>$v) {
                $indexId = $v['indexId'];
                list($aId,) = explode('_',$indexId);
                if ($activityId == $aId) {
                    $info[$k] = $v;
                }
            }
        }

        $activityChristmasList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_CHRISTMAS);
        $activityChristmas = $activityChristmasList->getElement($activityId,false);
        $activityChristmasInfo = array();
        if ($activityChristmas) {
            $activityChristmasInfo = $activityChristmas->toArray();
        }

        return array(
            'info' => $info,
            'honey' => $data,
            'status' => $status,
            'rank' => $myRank,
            'num' => $num,
            'christmas' => $activityChristmasInfo,
        );
    }

    /**
     * 万圣节活动开启格子
     * @param $userId
     * @param $activityId
     * @param $position
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activitySynthesisUnlockBox($userId,$activityId,$position,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

    /*    $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }*/
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($activity['type'] != self::ActivitySynthesis) {
            throw new SzException(90005);
        }

        /**
         * @var $activitySynthesisBoxList ActivitySynthesisBoxVoList
         * @var $activitySynthesisBox ActivitySynthesisBoxVo
         */
        $activitySynthesisBoxList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS_BOX);
        $activitySynthesisBox = $activitySynthesisBoxList->getElement($activityId.'_'.$position,false);
        if ($activitySynthesisBox) {
            throw new SzException(90055,$activityId.'_'.$position);
        }

        $num = 0;
        $activitySynthesisBoxSettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_SYNTHESIS_BOX,null, true);
        foreach ($activitySynthesisBoxSettings as $activitySynthesisBoxSetting) {
            if ($activityId != $activitySynthesisBoxSetting['activityId'] || $position != $activitySynthesisBoxSetting['position']) {
                continue;
            }
            $output = '';
            if (!$activitySynthesisBoxSetting['isFree']) {
                foreach ($activitySynthesisBoxSetting['unlockItems'] as $entryId=>$count) {
                    GameService::get()->handleEntity($userId, $entryId, $count, true, true);
                    $output .= $entryId.':'.$count.'|';
                    if ($entryId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                        $num = $count;
                    }
                }
                CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,0,$output,'activitySynthesisUnlockBox');//消耗资源上报
            }
            $activitySynthesisBox = new ActivitySynthesisBoxVo($userId,$activityId.'_'.$position,0,0,true);
            $activitySynthesisBoxList->addElement($activitySynthesisBox);
            $activitySynthesisBoxList->setElement($activityId.'_'.$position,$activitySynthesisBox);
            SzPersister::get()->setVoList($activitySynthesisBoxList);
            break;
        }

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:BuyQue|',
                'item' => $position,
                'value' => 1
            )
        ));

        if ($num) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'Hallows&BuyQue&'.$position,
                    'value' => $num
                )
            ));
        }

        return true;
    }

    /**
     * 万圣节活动合成道具
     * @param $userId
     * @param $activityId
     * @param $position
     * @param $synthesisId
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activitySynthesisItem($userId,$activityId,$position,$synthesisId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

   /*     $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }*/
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        /**
         * @var $activitySynthesisBoxList ActivitySynthesisBoxVoList
         * @var $activitySynthesisBox ActivitySynthesisBoxVo
         * @var $activitySynthesisList ActivitySynthesisVoList
         * @var $activitySynthesis ActivitySynthesisVo
         */
        $activitySynthesisBoxList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS_BOX);
        $activitySynthesisBox = $activitySynthesisBoxList->getElement($activityId.'_'.$position);
        if ($activitySynthesisBox->getSynthesisId()) {
            throw new SzException(90056,$activityId.'_'.$position);
        }

        $activitySynthesisSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_SYNTHESIS,$synthesisId, true);

        $input = '';
        foreach ($activitySynthesisSetting['consumable'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $input .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,0,$input,'activitySynthesisItem');//消耗资源上报

        $activitySynthesisBox->setSynthesisId($synthesisId);
        $activitySynthesisBox->setEndTime(($reqTime + $activitySynthesisSetting['synthesisTime']));
        $activitySynthesisBoxList->updateElement($activityId.'_'.$position,$activitySynthesisBox);
        SzPersister::get()->setVoList($activitySynthesisBoxList);

        $activitySynthesisList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS);
        $activitySynthesis = $activitySynthesisList->getElement($activityId,false);
        if (!$activitySynthesis) {
            $activitySynthesis = new ActivitySynthesisVo($userId,$activityId,0,0,true);
        }

        $number = $activitySynthesis->getNumber();
        $number+=$activitySynthesisSetting['num'];
        $activitySynthesis->setNumber($number);

        if ($activity['type'] == self::ActivitySynthesis) {
            $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
            $redisDb->zAdd(GameConst::CACHE_KEY_ACTIVITY_SYNTHESIS_RANK.$activityId,$number,$userId);
        }


        if ($activitySynthesis->isInsert() && !SzUtility::checkArrayKey($activityId, $activitySynthesisList->getList())) {
            $activitySynthesisList->addElement($activitySynthesis);
            $activitySynthesisList->setElement($activityId,$activitySynthesis);
        } else {
            $activitySynthesisList->updateElement($activityId,$activitySynthesis);
        }
        SzPersister::get()->setVoList($activitySynthesisList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:Candystart|',
                'item' => $synthesisId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
            'clientData' => array(
                'tid' => $input,
                'item' => 'Hallows&Candystart',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 万圣节活动清除时间
     * @param $userId
     * @param $activityId
     * @param $position
     * @param $platform
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activitySynthesisClearTime($userId,$activityId,$position,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

      /*  $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }*/
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        /**
         * @var $activitySynthesisBoxList ActivitySynthesisBoxVoList
         * @var $activitySynthesisBox ActivitySynthesisBoxVo
         */
        $activitySynthesisBoxList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS_BOX);
        $activitySynthesisBox = $activitySynthesisBoxList->getElement($activityId.'_'.$position);
        $synthesisId = $activitySynthesisBox->getSynthesisId();

        if (!$synthesisId) {
            throw new SzException(90057,$activityId.'_'.$position);
        }

        $data = array();
        if ($activitySynthesisBox->getEndTime() <= $reqTime) {
            return $data;
        }

        $activitySynthesisSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_SYNTHESIS,$synthesisId, true);

        $num = 0;
        $output = '';
        foreach ($activitySynthesisSetting['clearUpItemId'] as $entryId=>$count) {
            $count = ceil(($activitySynthesisBox->getEndTime() - $reqTime) / $activitySynthesisSetting['synthesisTime'] * $count);
            $data[$entryId] = $count;
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
            if ($entryId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $num = $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,0,$output,'activitySynthesisClearTime');//消耗资源上报

        $activitySynthesisBox->setEndTime($reqTime);
        $activitySynthesisBoxList->updateElement($activityId.'_'.$position,$activitySynthesisBox);
        SzPersister::get()->setVoList($activitySynthesisBoxList);

        if ($num) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'Hallows&CD&2',
                    'value' => $num,
                )
            ));
        }

        return $data;
    }

    /**
     * 万圣节活动领取道具
     * @param $userId
     * @param $activityId
     * @param $position
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activitySynthesisGetItem($userId,$activityId,$position,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

  /*      $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        /**
         * @var $activitySynthesisBoxList ActivitySynthesisBoxVoList
         * @var $activitySynthesisBox ActivitySynthesisBoxVo
         */

        $activitySynthesisBoxList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS_BOX);
        $activitySynthesisBox = $activitySynthesisBoxList->getElement($activityId.'_'.$position);
        $synthesisId = $activitySynthesisBox->getSynthesisId();

        if (!$synthesisId) {
            throw new SzException(90057,$activityId.'_'.$position);
        }

        if ($activitySynthesisBox->getEndTime() > $reqTime) {
            throw new SzException(90058,$activityId.'_'.$position);
        }

        $activitySynthesisSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_SYNTHESIS,$synthesisId, true);

        $output = '';
        foreach ($activitySynthesisSetting['synthetics'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,1,$output,'activitySynthesisGetItem');//获得资源上报

        $activitySynthesisBox->setEndTime(0);
        $activitySynthesisBox->setSynthesisId(0);
        $activitySynthesisBoxList->updateElement($activityId.'_'.$position,$activitySynthesisBox);
        SzPersister::get()->setVoList($activitySynthesisBoxList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:CandyEnd|',
                'item' => $synthesisId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'Hallows&CandyEnd',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 万圣节活动排行榜信息
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activitySynthesisRank($userId,$activityId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

    /*    $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis) {
            throw new SzException(90005);
        }

        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        $data = $redisDb->zRevRange(GameConst::CACHE_KEY_ACTIVITY_SYNTHESIS_RANK.$activityId,0,99,true);

        /**
         * @var $activitySynthesisList ActivitySynthesisVoList
         * @var $activitySynthesis ActivitySynthesisVo
         */
        $activitySynthesisList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS);
        $activitySynthesis = $activitySynthesisList->getElement($activityId,false);
        $myRank = $score = $rank = 0;
        if ($activitySynthesis) {
            $score = $activitySynthesis->getNumber();
        }

        $res = array(
            'rank' => array(),
            'myRank' => array(
                'index' => $myRank,
                'score' => $score,
            )
        );
        if ($data) {
            foreach ($data as $uId=>$number) {
                $rank++;
                $res['rank'][] = $this->getUserInfo($uId,$number);
                if ($uId == $userId) {
                    $res['myRank']['index'] = $rank;
                }
            }
        }
        return $res;
    }

    /**
     * 万圣节活动领取排行榜奖励
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activitySynthesisRankReward($userId,$activityId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $startTime = $activity['parms'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        /*
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];

        $endTime = strtotime($activity[$platformPre.'EndTime']);

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis) {
            throw new SzException(90005);
        }

        $activityHalloweenSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_HALLOWEEN,$activityId, true);

        /**
         * @var $activitySynthesisList ActivitySynthesisVoList
         * @var $activitySynthesis ActivitySynthesisVo
         */
        $activitySynthesisList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS);
        $activitySynthesis = $activitySynthesisList->getElement($activityId);

        if ($activitySynthesis->getStatus()) {
            throw new SzException(90007);
        }

        $output = '';
        $index = count($activityHalloweenSetting['halloweenScore']) - 1;
        if ($activitySynthesis->getNumber() >= $activityHalloweenSetting['minNum']) {
            foreach (json_decode($activityHalloweenSetting['halloweenAward'],true)[$index] as $entryId=>$count) {
                GameService::get()->handleEntity($userId, $entryId, $count, true, true);
                $output .= $entryId.':'.$count.'|';
            }
        }

        $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
        $data = $redisDb->zRevRange(GameConst::CACHE_KEY_ACTIVITY_SYNTHESIS_RANK.$activityId,0,99,true);

        $myRank = $rank = 0;

        if ($data) {
            foreach ($data as $uId=>$number) {
                $rank++;
                if ($userId == $uId) {
                    $myRank = $rank;
                }
            }
        }


        if ($myRank > 0) {
            foreach ($activityHalloweenSetting['halloweenScore'] as $key=>$value) {
                if ($myRank <= $value) {
                    $index = $key;
                    break;
                }
            }
            foreach (json_decode($activityHalloweenSetting['halloweenAward'],true)[$index] as $entryId=>$count) {
                GameService::get()->handleEntity($userId, $entryId, $count, true, true);
                $output .= $entryId.':'.$count.'|';
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,1,$output,'activitySynthesisRankReward');//获得资源上报

        $activitySynthesis->setStatus(1);
        $activitySynthesisList->updateElement($activityId,$activitySynthesis);
        SzPersister::get()->setVoList($activitySynthesisList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:Reward|',
                'item' => $myRank,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'Hallows&Reward&'.$myRank,
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 万圣节活动兑换
     * @param $userId
     * @param $activityId
     * @param $exchangeId
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activitySynthesisExchange($userId,$activityId,$exchangeId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
 /*       $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        $activityExchangeSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_EXCHANGE,$exchangeId, true);

        if ($activityExchangeSetting['type'] != $activityId) {
            throw new SzException(80001,GameConst::CONFIG_GAME_ACTIVITY_EXCHANGE.'-'.$activityId.'_'.$activityExchangeSetting['type']);
        }
        $output = $input = '';

        foreach ($activityExchangeSetting['expend'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $input .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,0,$input,'activitySynthesisExchange');//消耗资源上报

   /*     if ($activityExchangeSetting['trimmingId']) {
            foreach ($activityExchangeSetting['reward'] as $entryId=>$count) {
                $output .= $entryId.':'.$count.'|';
            }
            $profileInfoList = SzPersister::get()->getVoList($userId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);
            $trimmingInfo = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_TRIMMING_INFO, $profileInfoList);
            if (is_null($trimmingInfo)) {
                $trimmingInfo = [];
            }
            if (!in_array($activityExchangeSetting['trimmingId'], $trimmingInfo)) {
                $trimmingInfo[] = $activityExchangeSetting['trimmingId'];
                UserService::get()->updateProfileInfo($userId, GameConst::USER_INFO_TYPE_TRIMMING_INFO, $trimmingInfo, $profileInfoList);
            }
        }*/
        if ($activityExchangeSetting['trimmingId']==1111) {//zhangpeng  20191009 特殊处理，只能兑换一次
            foreach ($activityExchangeSetting['reward'] as $entryId=>$count) {
                $itemList = SzPersister::get()->getVoList($userId, ModuleItemConst::ORM_NAME_ITEM);
                list($action, $module, $itemDefId) = EntityService::get()->parseEntityId($entryId);
                if ($action == GameConst::ENTITY_ACTION_GET && $module == GameConst::ENTITY_TYPE_ITEM) {
                    $itemSetting = SzConfig::get()->loadAppConfig(ModuleItemConst::CONFIG_ITEM_DEFS, $itemDefId, true);
                    if ($itemSetting['category'] == GameConst::ITEM_CATEGORY_CULTIVATE_CARD) {
                        $item = $itemList->getElementsByItemDefId($itemDefId);
                        if ($item) {//如果有这朵花就不能兑换了
                            continue;
                        }
                    }
                }
                 GameService::get()->handleEntity($userId, $entryId, $count, true, true);
                 $output .= $entryId.':'.$count.'|';
            }
        } else {
            foreach ($activityExchangeSetting['reward'] as $entryId=>$count) {
                GameService::get()->handleEntity($userId, $entryId, $count, true, true);
                $output .= $entryId.':'.$count.'|';
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,1,$output,'activitySynthesisExchange');//获得资源上报

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:Exchange|',
                'item' => $exchangeId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
            'clientData' => array(
                'tid' =>$input,
                'item' => 'Hallows&Exchange',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'Hallows&Exchange',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 万圣节活动制作蜂蜜
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return int
     * @throws SzException
     */
    public function activityMakeHoney($userId,$activityId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
 /*       $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }


        $activityHalloweenSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_HALLOWEEN,$activityId, true);

        /**
         * @var $activityMakeHoneyList ActivityMakeHoneyVoList
         * @var $activityMakeHoney ActivityMakeHoneyVo
         */
        $activityMakeHoneyList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_MAKE_HONEY);
        $activityMakeHoney = $activityMakeHoneyList->getElement($activityId, false);

        if (!$activityMakeHoney) {
            $activityMakeHoney = new ActivityMakeHoneyVo($userId,$activityId,0,true);
        } else if ($activityMakeHoney->getEndTime()) {
            throw new SzException(90059);
        }

        $endTime = $activityHalloweenSetting['beeTime'] + $reqTime;
        $activityMakeHoney->setEndTime($endTime);

        if ($activityMakeHoney->isInsert() && !SzUtility::checkArrayKey($activityId, $activityMakeHoneyList->getList())) {
            $activityMakeHoneyList->addElement($activityMakeHoney);
            $activityMakeHoneyList->setElement($activityId,$activityMakeHoney);
        } else {
            $activityMakeHoneyList->updateElement($activityId,$activityMakeHoney);
        }
        SzPersister::get()->setVoList($activityMakeHoneyList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:HoneyStart|',
                'item' => 'honey',
                'value' => 1
            )
        ));

        return $endTime;
    }

    /**
     * 万圣节活动加速蜂蜜
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityMakeHoneySeedUp($userId,$activityId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

  /*      $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['parms'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        $activityHalloweenSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_HALLOWEEN,$activityId, true);

        /**
         * @var $activityMakeHoneyList ActivityMakeHoneyVoList
         * @var $activityMakeHoney ActivityMakeHoneyVo
         */
        $activityMakeHoneyList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_MAKE_HONEY);
        $activityMakeHoney = $activityMakeHoneyList->getElement($activityId);

        $data = array();

        if ($activityMakeHoney->getEndTime() <= $reqTime) {
            return $data;
        }


        $num = 0;
        $output = '';
        foreach ($activityHalloweenSetting['beePrice'] as $entryId=>$count) {
            $count = ceil(($activityMakeHoney->getEndTime() - $reqTime) /  $activityHalloweenSetting['beeTime'] * $count);
            $data[$entryId] = $count;
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            if ($entryId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $num = $count;
            }
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,0,$output,'activityMakeHoneySeedUp');//获得资源上报

        $activityMakeHoney->setEndTime($reqTime);

        $activityMakeHoneyList->updateElement($activityId,$activityMakeHoney);

        SzPersister::get()->setVoList($activityMakeHoneyList);

        if ($num) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'Hallows&CD&1',
                    'value' => $num
                )
            ));
        }

        return $data;
    }

    /**
     * 万圣节活动领取蜂蜜
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityMakeHoneyReward($userId,$activityId,$platform,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

  /*      $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }*/

        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivitySynthesis && $activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        $activityHalloweenSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_HALLOWEEN,$activityId, true);

        /**
         * @var $activityMakeHoneyList ActivityMakeHoneyVoList
         * @var $activityMakeHoney ActivityMakeHoneyVo
         */
        $activityMakeHoneyList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_MAKE_HONEY);
        $activityMakeHoney = $activityMakeHoneyList->getElement($activityId);

        if (!$activityMakeHoney->getEndTime()) {
            throw new SzException(90060);
        }

        if ($activityMakeHoney->getEndTime() > $reqTime) {
            throw new SzException(90061,$activityMakeHoney->getEndTime() .'-'.$reqTime);
        }
        $output = '';
        foreach ($activityHalloweenSetting['beeNum'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,1,$output,'activityMakeHoneyReward');//获得资源上报

        $activityMakeHoney->setEndTime(0);
        $activityMakeHoneyList->updateElement($activityId,$activityMakeHoney);
        SzPersister::get()->setVoList($activityMakeHoneyList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:HoneyEnd|',
                'item' => 'honey',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'Hollows&HoneyEnd',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 获取好友信息
     * @param $friendId
     * @param $score
     * @return array
     * @throws SzException
     */
    public function getUserInfo($friendId,$score) {
        $profileInfoList = SzPersister::get()->getVoList($friendId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);

        $res = array(
            'userId' => $friendId,
            'userLevel' => UserService::get()->getUserLevel($friendId),
            'townName' => UserService::get()->getTownName($friendId, $profileInfoList),
            'headImgId' => UserService::get()->getHeadIcon($friendId, $profileInfoList),
            'gender' => UserService::get()->getGender($friendId,$profileInfoList),
            'score' => $score,
            'flowerLevel' => UserService::get()->getFlowerLevel($friendId,$profileInfoList),
            'flowerLevelExpireTime' => UserService::get()->getFlowerLevelExpireTime($friendId,$profileInfoList),
        );

        //获取玩家的头像框数据
        $profileInfo = $profileInfoList->getElement(GameConst::USER_INFO_TYPE_HEAD_FRAME,false);
        if (!$profileInfo){
            $res['headFrame'] = 0;
        }
        else{
            $res['headFrame'] = $profileInfo->getInfo();
        }

        return $res;
    }


    /**
     * 圣诞节领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityChristmasReward($userId,$activityId,$indexId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        /**
         * @var $activitySynthesisList ActivitySynthesisVoList
         * @var $activitySynthesis ActivitySynthesisVo
         * @var $activityChristmasList ActivityChristmasVoList
         * @var $activityChristmas ActivityChristmasVo
         */
        $activitySynthesisList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_SYNTHESIS);
        $activitySynthesis = $activitySynthesisList->getElement($activityId,false);
        $num = 0;
        if ($activitySynthesis) {
            $num = $activitySynthesis->getNumber();
        }

        $activityChristmasList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_CHRISTMAS);
        $activityChristmas = $activityChristmasList->getElement($activityId,false);
        if (!$activityChristmas) {
            $activityChristmas = new ActivityChristmasVo($userId,$activityId,[],true);
        }

        $info = $activityChristmas->getRawInfo();
        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        $activityHalloweenSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_HALLOWEEN,$activityId, true);

        $activityHalloweenSetting['halloweenAward'] = json_decode($activityHalloweenSetting['halloweenAward'],true);
        if (!isset($activityHalloweenSetting['halloweenScore'][$indexId]) || !isset($activityHalloweenSetting['halloweenAward'][$indexId])) {
            throw new SzException(90062);
        }

        if ($num < $activityHalloweenSetting['halloweenScore'][$indexId]) {
            throw new SzException(90062);
        }

        $output = '';
        foreach ($activityHalloweenSetting['halloweenAward'][$indexId] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,1,$output,'activityChristmasReward');//获得资源上报

        $info[] = $indexId;
        $activityChristmas->setInfo($info);

        if ($activityChristmas->isInsert() && !SzUtility::checkArrayKey($activityId, $activityChristmasList->getList())) {
            $activityChristmasList->addElement($activityChristmas);
            $activityChristmasList->setElement($activityId,$activityChristmas);
        } else {
            $activityChristmasList->updateElement($activityId,$activityChristmas);
        }

        SzPersister::get()->setVoList($activityChristmasList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:Hallows|action:FreeAmount|',
                'item' => $num,
                'value' => 1
            )
        ));


        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'Hallows&FreeAmount',
                'value' => 1
            )
        ));



        return $activityChristmas->toArray();
    }

    /**
     * 购买礼包
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityChristmasBuy($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityChristmas) {
            throw new SzException(90005);
        }

        $activityHalloweenSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_HALLOWEEN,$activityId, true);

        /**
         * @var ModuleProfileInfoVoList $profileInfoList
         * @var ModuleProfileInfoVo $christmasProfileInfo
         */
        $profileInfoList = SzPersister::get()->getVoList($userId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);
        $christmasProfileInfo = $profileInfoList->getElement(GameConst::USER_INFO_TYPE_CHRISTMAS, false);

        if (!$christmasProfileInfo) {
            $christmasProfileInfo = new ModuleProfileInfoVo(
                $userId,
                GameConst::USER_INFO_TYPE_CHRISTMAS,
                $reqTime,
                $reqTime,
                true
            );
        }

        if ($reqTime < (int)$christmasProfileInfo->getRawInfo()) {
            return false;
        }

        $useGold = 0;
        $input = '';
        foreach ($activityHalloweenSetting['giftPrice'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            if ($entryId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
            $input .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,0,$input,'activityChristmasBuy');//消耗资源上报

        $output = '';
        foreach ($activityHalloweenSetting['halloweenGift'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(GameConst::FUNC_HALLOWEEN,$userId,1,$output,'activityChristmasBuy');//获得资源上报

        $christmasProfileInfo->setInfo($reqTime + $activityHalloweenSetting['giftTime']);
        $christmasProfileInfo->setTime($reqTime);

        if ($christmasProfileInfo->isInsert() && !SzUtility::checkArrayKey(GameConst::USER_INFO_TYPE_CHRISTMAS, $profileInfoList->getList())) {
            $profileInfoList->addElement($christmasProfileInfo);
            $profileInfoList->setElement(GameConst::USER_INFO_TYPE_CHRISTMAS,$christmasProfileInfo);
        } else {
            $profileInfoList->updateElement(GameConst::USER_INFO_TYPE_CHRISTMAS,$christmasProfileInfo);
        }

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' => $output,
                'item' => 'Hallows&Gift',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'Hallows&Gift',
                    'value' => $useGold
                )
            ));
        }

        return true;

    }
    /***********************************首充活动*********************************************/
    /**
     * @param $userId
     * @param $activityId
     * @param $sign
     * @param $money
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityFirstPay($userId, $activityId, $sign, $money, $reqTime) {
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        if ($platform != 'qtt'){
            if (!CommonFunctionService::get()->redisFlagCheck(GameConst::CACHE_KEY_ACTIVITY_FIRST_PAY,$userId,$reqTime)) {
                throw new SzException(90111);
            }

            if (!CommonFunctionService::get()->checkMd5($sign,$reqTime)){
                throw new SzException(90110);
            }
        }

        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= ($reqTime + 100)) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityFirstPay) {
            throw new SzException(90005);
        }

        $gamePaySettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_PAY, null, true);
        $reward = array();
        foreach ($gamePaySettings as $gamePaySetting) {
            if ($gamePaySetting['count'] == $money) {
                $reward = $gamePaySetting;
                break;
            }
        }

        if (!$reward) {
            throw new SzException(90062);
        }

        /**
         * @var $activityFirstPayList ActivityFirstPayVoList
         * @var $activityFirstPay ActivityFirstPayVo
         */
        $activityFirstPayList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_FIRST_PAY);
        $activityFirstPay = $activityFirstPayList->getElement($money,false);
        if ($activityFirstPay) {
            if ($activityFirstPay->getBatch() == $activityId) {
                throw new SzException(90062);
            }
            $activityFirstPay->setBatch($activity['parms']);
            $activityFirstPay->setUpdateTime($reqTime);
        } else {
            $activityFirstPay = new ActivityFirstPayVo($userId,$money,$activityId,$reqTime,true);
        }
        if ($activityFirstPay->isInsert() && !SzUtility::checkArrayKey($money, $activityFirstPayList->getList())) {
            $activityFirstPayList->addElement($activityFirstPay);
            $activityFirstPayList->setElement($money,$activityFirstPay);
        } else {
            $activityFirstPayList->updateElement($money,$activityFirstPay);
        }

        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_GET_MONEY, $money, true);
        CommonFunctionService::get()->reportResourceUseDetails(99999980,$userId,1,GameConst::ENTITY_ACTION_GET_MONEY.':'.$money.'|','activityFirstPay');//获得资源上报

        SzPersister::get()->setVoList($activityFirstPayList);

        return true;
    }

    /***********************************转盘抽奖*********************************************/
    /**
     * 转盘抽奖信息
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityLotteryInfo($userId, $activityId, $platform,$reqTime) {
        $activityType = $this->currencyCheckActivityRangeTime($activityId, $platform, $reqTime);
        if ($activityType != self::ActivityLottery) {
            throw new SzException(90005);
        }

        /**
         * @var $activityLotteryList ActivityLotteryVoList
         * @var $activityLottery ActivityLotteryVo
         */
        $activityLotteryList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_LOTTERY);
        $activityLottery = $activityLotteryList->getElement($activityId,false);
        if (!$activityLottery) {
            return array();
        }
        return $activityLotteryList->toArray();
    }

    /**
     * 转盘抽奖
     * @param $userId
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return int
     * @throws SzException
     */
    public function activityLotteryReward($userId, $activityId, $platform, $reqTime) {
        $activityType = $this->currencyCheckActivityRangeTime($activityId, $platform, $reqTime);
        if ($activityType != self::ActivityLottery) {
            throw new SzException(90005);
        }

        /**
         * @var $activityLotteryList ActivityLotteryVoList
         * @var $activityLottery ActivityLotteryVo
         */
        $activityLotteryList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_LOTTERY);
        $activityLottery = $activityLotteryList->getElement($activityId,false);
        if (!$activityLottery) {
            $activityLottery = new ActivityLotteryVo($userId,$activityId,[],true);
        }

        $info = $activityLottery->getRawInfo();
        $num = count($info) + 1;

        $activityLotterySetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_LOTTERY, $num, true);

        foreach ($activityLotterySetting['lotteryProbability'] as $k=>$v) {
            if ($v == 0) {
                unset($activityLotterySetting['lotteryProbability'][$k]);
                continue;
            }
            if (in_array($k,$info)) {
                unset($activityLotterySetting['lotteryProbability'][$k]);
                continue;
            }
        }

        $id = SzUtility::getRandomElementByProbability($activityLotterySetting['lotteryProbability']);

        $curSettings = array();
        $activityLotteryRewardSettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_LOTTERY_REWARD, null, true);
        foreach ($activityLotteryRewardSettings as $key=>$data){
            if ($data['eventId'] == $activityId){
                $curSettings[$data['id']] = $data;
            }
        }


//        $activityLotteryRewardSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_LOTTERY_REWARD, $id, true);
        $activityLotteryRewardSetting = array();
        if (!empty($curSettings[$id])){
            $activityLotteryRewardSetting = $curSettings[$id];
        }
        else{
            throw new SzException(90082);
        }

        $output = $input = '';
        $useGold = 0;
        $isFree = 1;
        foreach ($activityLotterySetting['diamondConsumption'] as $entryId=>$count) {
            if ($count == 0) {
                $isFree = 0;
                continue;
            }
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            if ($entryId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            } else {
                $input .= $entryId.':'.$count.'|';
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999987,$userId,0,$input,'activityLotteryReward');//消耗资源上报

        foreach ($activityLotteryRewardSetting['reward'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999987,$userId,1,$output,'activityLotteryReward');//获得资源上报

        $info[] = $id;
        $activityLottery->setInfo($info);

        if ($activityLottery->isInsert() && !SzUtility::checkArrayKey($activityId, $activityLotteryList->getList())) {
            $activityLotteryList->addElement($activityLottery);
            $activityLotteryList->setElement($activityId,$activityLottery);
        } else {
            $activityLotteryList->updateElement($activityId,$activityLottery);
        }

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:lotterySys|action:start|',
                'item' => $isFree,
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'lotterySysStart',
                    'value' => $useGold
                )
            ));
        }

        if ($input) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
                'clientData' => array(
                    'tid' =>$input,
                    'item' => 'lotterySysStart',
                    'value' => 1
                )
            ));
        }

        if ($output) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' =>$output,
                    'item' => 'lotterySysEnd',
                    'value' => 1
                )
            ));
        }

        SzPersister::get()->setVoList($activityLotteryList);

        return $id;
    }

    /***********************************充值活动*********************************************/
    /**
     * 活动信息
     * @param $userId
     * @param $activityId
     * @return array
     * @throws SzException
     */
    public function activityPayInfo($userId, $activityId) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        /**
         * @var $activityPayList ActivityPayVoList
         * @var $activityPay ActivityPayVo
         */
        $activityPayList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PAY);
        $activityPay = $activityPayList->getElement($activityId,false);

        $data = array();
        if ($activityPay) {
            $data = $activityPay->toArray();
        }

        return $data;
    }

    /**
     * @param $userId
     * @param $activityId
     * @param $sign
     * @param $money
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityPay($userId, $activityId, $sign, $money, $platform, $reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

      /*  $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= ($reqTime + 100)) {
            throw new SzException(90002);
        }*/

        //20190827 zhangpeng
        //qq 跟wanba 用的同一个配置
        if ($platform=='qq') {
            $platform='wanba';
        }

        if (($activity[$platform.'TriggerTime'] && $activity[$platform.'TriggerTime'] != '' && $activity[$platform.'TriggerTime'] != null && !empty($activity[$platform.'TriggerTime']))
            && ($activity[$platform.'EndTime'] && $activity[$platform.'EndTime'] != '' && $activity[$platform.'EndTime'] != null && !empty($activity[$platform.'EndTime']))){
            $startTime = strtotime($activity[$platform.'TriggerTime']);
            $endTime = strtotime($activity[$platform.'EndTime']);
        }
        else{
            $startTime = $activity['startTime'];
            $endTime = $activity['endTime'];
        }


        if ($startTime > $reqTime) {
            return array(
                'code' => GameConst::CODE_1091
            );
        }elseif ($endTime <= ($reqTime + 100)) {
            return array(
                'code' => GameConst::CODE_1092
            );
        }


        if ($activity['type'] != self::ActivityPay) {
            throw new SzException(90005);
        }

        if ($sign != md5(self::PrivateKey.$reqTime)) {
            throw new SzException(90062);
        }

        /**
         * @var $activityPayList ActivityPayVoList
         * @var $activityPay ActivityPayVo
         */
        $activityPayList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PAY);
        $activityPay = $activityPayList->getElement($activityId,false);

        if (!$activityPay) {
            $activityPay = new ActivityPayVo($userId,$activityId,[],0,true);
        }

        $activityPay->updateMoneyNum($money);

        if ($activityPay->isInsert() && !SzUtility::checkArrayKey($activityId, $activityPayList->getList())) {
            $activityPayList->addElement($activityPay);
            $activityPayList->setElement($activityId,$activityPay);
        } else {
            $activityPayList->updateElement($activityId,$activityPay);
        }

        SzPersister::get()->setVoList($activityPayList);

        return true;
    }

    /**
     * 充值活动领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $isBuy
     * @param $platform
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityPayReward($userId, $activityId, $indexId, $isBuy, $platform, $reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        //20190827 zhangpeng
        $platform = GameConst::PLATFORM_TIME_ARRAY[$platform];

        if (($activity[$platform.'TriggerTime'] && $activity[$platform.'TriggerTime'] != '' && $activity[$platform.'TriggerTime'] != null && !empty($activity[$platform.'TriggerTime']))
            && ($activity[$platform.'EndTime'] && $activity[$platform.'EndTime'] != '' && $activity[$platform.'EndTime'] != null && !empty($activity[$platform.'EndTime']))){
            $startTime = strtotime($activity[$platform.'TriggerTime']);
            $endTime = strtotime($activity[$platform.'EndTime']);
        }
        else{
            $startTime = $activity['startTime'];
            $endTime = $activity['endTime'];
        }


        if ($startTime > $reqTime) {
            return array(
                'code' => GameConst::CODE_1091
            );
        }elseif ($endTime <= ($reqTime + 100)) {
            return array(
                'code' => GameConst::CODE_1092
            );
        }

        if ($activity['type'] != self::ActivityPay) {
            throw new SzException(90005);
        }

        /**
         * @var $activityPayList ActivityPayVoList
         * @var $activityPay ActivityPayVo
         */
        $activityPayList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PAY);
        $activityPay = $activityPayList->getElement($activityId,false);

        if (!$activityPay) {
            $activityPay = new ActivityPayVo($userId,$activityId,[],0,true);
        }

        $activityRebateSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_REBATE, $indexId, true);

        $info = $activityPay->getRawInfo();
        $info = $info ? $info : array();

        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        if ($activityRebateSetting['accumulatedRecharge'] > $activityPay->getMoneyNum() && !$isBuy) {
            throw new SzException(90065);
        }

        $useGold = 0;

        // 扣除钻石
        if ($activityRebateSetting['accumulatedRecharge'] > $activityPay->getMoneyNum() && $isBuy) {
            GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_CONSUME_MONEY, $activityRebateSetting['directPurchase'], true);
            CommonFunctionService::get()->reportResourceUseDetails(99999979,$userId,0,GameConst::ENTITY_ACTION_CONSUME_MONEY.':'.$activityRebateSetting['directPurchase'].'|','activityPayReward');//消耗资源上报
            $activityPay->setMoneyNum($activityRebateSetting['accumulatedRecharge']);
            $useGold = $activityRebateSetting['directPurchase'];
        }

        $output = '';
        foreach ($activityRebateSetting['reward'] as $entryId=>$count) {
            GameService::get()->handleEntity($userId, $entryId, $count, true, true);
            $output .= $entryId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999979,$userId,1,$output,'activityPayReward');//获得资源上报

        $info[] = $indexId;
        $activityPay->setInfo($info);

        if ($activityPay->isInsert() && !SzUtility::checkArrayKey($activityId, $activityPayList->getList())) {
            $activityPayList->addElement($activityPay);
            $activityPayList->setElement($activityId,$activityPay);
        } else {
            $activityPayList->updateElement($activityId,$activityPay);
        }

        SzPersister::get()->setVoList($activityPayList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:payActivity|action:get|',
                'item' => $indexId,
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'payActivity_get&'.$indexId,
                    'value' => $useGold
                )
            ));
        }

        if ($output) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' =>$output,
                    'item' => 'payActivity_get&'.$indexId,
                    'value' => 1
                )
            ));
        }


        return true;
    }

    /***********************************春节树活动*********************************************/
    /**
     * 活动信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityTreeInfo($userId,$activityId,$reqTime) {
        $res = array(
            'code' => 0,
            'data' => array()
        );

        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if (!$activity || empty($activity)){
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['CONFIG_NOT_EXIST'];//配置不存在
            return $res;
        }
        if ($startTime > $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['START_ERR'];//开始时间错误

        }
        if ($endTime <= $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['END_ERR'];//结束时间错误
        }
        if ($activity['type'] != self::ActivityTree) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['ACT_TYPE_ERR'];//活动类型错误
        }

        /**
         * @var $activityTreeInfoList ActivityTreeInfoVoList
         * @var $activityTreeInfo ActivityTreeInfoVo
         */
        $activityTreeInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TREE_INFO);
        $activityTreeInfo = $activityTreeInfoList->getElement($activityId,false);

        $data = array();

        if ($activityTreeInfo) {
            $activityTreeCostNum = SzConfig::get()->loadAppConfig(ModuleProfileConst::CONFIG_PROFILE, 'activityTreeCostNum', true);
            $activityTreeCostNum = $activityTreeCostNum['value'];
            $noCalculated = $activityTreeInfo->getNoCalculated();

            $profileInfoList = SzPersister::get()->getVoList($userId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);
            $treeStatusProfileInfo = $profileInfoList->getElement(GameConst::USER_INFO_TYPE_TREE_STATUS, false);

            $isUpdate = false;
            if (!$treeStatusProfileInfo) {
                $treeStatusProfileInfo = new ModuleProfileInfoVo(
                    $userId,
                    GameConst::USER_INFO_TYPE_TREE_STATUS,
                    1,
                    GameService::get()->getReqTime(),
                    true
                );
                $profileInfoList->addElement($treeStatusProfileInfo);
                $profileInfoList->setElement(GameConst::USER_INFO_TYPE_TREE_STATUS, $treeStatusProfileInfo);
                SzPersister::get()->setVoList($profileInfoList);
                $activityTreeInfo->setInfo(array());
                $isUpdate = true;
            }

            if ($noCalculated >= $activityTreeCostNum) {
                $activityTreeGetNum = SzConfig::get()->loadAppConfig(ModuleProfileConst::CONFIG_PROFILE, 'activityTreeGetNum', true);
                $activityTreeGetNum = $activityTreeGetNum['value'];
                $surplus = $noCalculated % $activityTreeCostNum;
                $num = intval($noCalculated / $activityTreeCostNum);

                $activityTreeInfo->updateTotalNum(($num * $activityTreeGetNum));

                $activityTreeInfo->setNoCalculated($surplus);
                $isUpdate = true;

                StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                    'clientData' => array(
                        'tid' => 'Module:spring|action:produce|',
                        'item' => GameConst::ENTITY_ACTION_CONSUME_ACTIVITY_TREE_GET.'&'.($num * $activityTreeGetNum),
                        'value' => 1
                    )
                ));

                $userLevel = UserService::get()->getUserLevel($userId);
                StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                    'clientData' => array(
                        'tid' => 'Module:tree|action:activityTreeInfo|',
                        'item' => 'itemsNum',
                        'value' => 1,
                        'value2' => $userLevel
                    )
                ));
            }
            $data = $activityTreeInfo->toArray();
            if ($isUpdate) {
                $activityTreeInfoList->updateElement($activityId, $activityTreeInfo);
                SzPersister::get()->setVoList($activityTreeInfoList);
            }
        }

        $res['data'] = $data;
        return $res;
    }

    /**
     * 抽奖
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityTreeLottery($userId,$activityId,$reqTime) {
        $res = array(
            'code' => 0,
            'state' => false
        );

        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if (!$activity || empty($activity)){
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['CONFIG_NOT_EXIST'];//配置不存在
            return $res;
        }
        if ($startTime > $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['START_ERR'];//开始时间错误

        }
        if ($endTime <= $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['END_ERR'];//结束时间错误
        }
        if ($activity['type'] != self::ActivityTree) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['ACT_TYPE_ERR'];//活动类型错误
        }

        /**
         * @var $activityTreeInfoList ActivityTreeInfoVoList
         * @var $activityTreeInfo ActivityTreeInfoVo
         */
        $activityTreeInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TREE_INFO);
        $activityTreeInfo = $activityTreeInfoList->getElement($activityId,false);

        if (!$activityTreeInfo) {
            $activityTreeInfo = new ActivityTreeInfoVo($userId,$activityId,[],[],0,0,0,$reqTime,0,true);
        }

        if (date('Y-m-d',$reqTime) != date('Y-m-d',$activityTreeInfo->getUpdateTime())) {
            $activityTreeInfo->setUpdateTime($reqTime);
            $activityTreeInfo->setNumber(0);
        }

        $number = $activityTreeInfo->getNumber();
        $number++;

        $activityTreeSettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_TREE, null, true);

        if (isset($activityTreeSettings[$number])) {
            $activityTreeSetting = $activityTreeSettings[$number];
        } else {
            $c = count($activityTreeSettings);
            $activityTreeSetting = $activityTreeSettings[$c];
        }


        $useGold = 0;
        $output = $input = '';
        foreach ($activityTreeSetting['costItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $input .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999986,$userId,0,$input,'activityTreeLottery');//消耗资源上报

        $addNum = 0;
        foreach ($activityTreeSetting['getItem'] as $entityId => $count) {
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_ACTIVITY_TREE_GET) {
                $addNum += $count;
            } else {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
            }

            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999986,$userId,1,$output,'activityTreeLottery');//获得资源上报

        $activityTreeInfo->setNumber($number);
        $activityTreeInfo->updateTotalNum($addNum);

        if ( $activityTreeInfo->isInsert() && !SzUtility::checkArrayKey($activityId,  $activityTreeInfoList->getList())) {
            $activityTreeInfoList->addElement( $activityTreeInfo);
            $activityTreeInfoList->setElement($activityId, $activityTreeInfo);
        } else {
            $activityTreeInfoList->updateElement($activityId, $activityTreeInfo);
        }

        SzPersister::get()->setVoList($activityTreeInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:spring|action:lottery|',
                'item' => 'spring_lottery',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'spring_lottery',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'spring_lottery',
                    'value' => $useGold
                )
            ));
        }

        $userLevel = UserService::get()->getUserLevel($userId);
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:tree|action:activityTreeLottery|',
                'item' => 'useTimes',
                'value' => 1,
                'value2' => $userLevel
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:tree|action:activityTreeLottery|',
                'item' => 'itemsNum',
                'value' => $addNum,
                'value2' => $userLevel
            )
        ));


        $res['state'] = true;
        return $res;
    }

    /**
     * 领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityTreeReward($userId,$activityId,$indexId,$reqTime) {
        $res = array(
            'code' => 0,
            'state' => false
        );

        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if (!$activity || empty($activity)){
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['CONFIG_NOT_EXIST'];//配置不存在
            return $res;
        }
        if ($startTime > $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['START_ERR'];//开始时间错误

        }
        if ($endTime <= $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['END_ERR'];//结束时间错误
        }
        if ($activity['type'] != self::ActivityTree) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['ACT_TYPE_ERR'];//活动类型错误
        }

        /**
         * @var $activityTreeInfoList ActivityTreeInfoVoList
         * @var $activityTreeInfo ActivityTreeInfoVo
         */
        $activityTreeInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TREE_INFO);
        $activityTreeInfo = $activityTreeInfoList->getElement($activityId);

        $info = $activityTreeInfo->getRawInfo();

        $info = $info ? $info : array();

        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        $activityTreeRewardSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_TREE_REWARD, $indexId, true);

        $score = $activityTreeRewardSetting['score'];
        if ($score > $activityTreeInfo->getTotalNum()) {
            throw new SzException(90062);
        }

        $output= '';
        foreach ($activityTreeRewardSetting['reward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999986,$userId,1,$output,'activityTreeReward');//获得资源上报

        $info[] = $indexId;
        $activityTreeInfo->setInfo($info);
        $activityTreeInfoList->updateElement($activityId, $activityTreeInfo);
        SzPersister::get()->setVoList($activityTreeInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:spring|action:reward|',
                'item' => $score,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'spring_reward&'.$score,
                'value' => 1
            )
        ));

        $userLevel = UserService::get()->getUserLevel($userId);
        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:tree|action:activityTreeReward|',
                'item' => $indexId,
                'value' => 1,
                'value2' => $userLevel
            )
        ));

        $res['state'] = true;
        return $res;
    }

    /**
     * 兑换
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityTreeExchange($userId,$activityId,$indexId,$reqTime) {
        $res = array(
            'code' => 0,
            'state' => false
        );

        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if (!$activity || empty($activity)){
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['CONFIG_NOT_EXIST'];//配置不存在
            return $res;
        }
        if ($startTime > $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['START_ERR'];//开始时间错误

        }
        if ($endTime <= $reqTime) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['END_ERR'];//结束时间错误
        }
        if ($activity['type'] != self::ActivityTree) {
            $res['code'] = GameConst::EXCEPTION_CODE_ARRAY['ACT_TYPE_ERR'];//活动类型错误
        }

        /**
         * @var $activityTreeInfoList ActivityTreeInfoVoList
         * @var $activityTreeInfo ActivityTreeInfoVo
         */
        $activityTreeInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TREE_INFO);
        $activityTreeInfo = $activityTreeInfoList->getElement($activityId);

        $info = $activityTreeInfo->getRawExchangeInfo();
        $info = $info ? $info : array();

        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        $activityTreeExchangeSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_TREE_EXCHANGE, $indexId, true);

        $input = $output = '';
        $addNum = 0;
        foreach ($activityTreeExchangeSetting['costItem'] as $entityId => $count) {
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_ACTIVITY_TREE_COST ) {
                $addNum += $count;
            } else {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
            }
            $input .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999986,$userId,0,$input,'activityTreeExchange');//消耗资源上报

        if ($addNum > ($activityTreeInfo->getTotalNum() - $activityTreeInfo->getUseNum())) {
            throw new SzException(90069);
        }

        foreach ($activityTreeExchangeSetting['getItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999986,$userId,1,$output,'activityTreeExchange');//获得资源上报

        if ($activityTreeExchangeSetting['trimmingId']) {
            $profileInfoList = SzPersister::get()->getVoList($userId, ModuleProfileConst::ORM_NAME_PROFILE_INFO);
            $trimmingInfo = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_TRIMMING_INFO, $profileInfoList);
            if (is_null($trimmingInfo)) {
                $trimmingInfo = [];
            }
            if (!in_array($activityTreeExchangeSetting['trimmingId'], $trimmingInfo)) {
                $trimmingInfo[] = $activityTreeExchangeSetting['trimmingId'];
                UserService::get()->updateProfileInfo($userId, GameConst::USER_INFO_TYPE_TRIMMING_INFO, $trimmingInfo, $profileInfoList);
            }
            $info[] = $indexId;
            $activityTreeInfo->setExchangeInfo($info);
        }

        $activityTreeInfo->updateUseNum($addNum);
        $activityTreeInfoList->updateElement($activityId, $activityTreeInfo);
        SzPersister::get()->setVoList($activityTreeInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:spring|action:exchange|',
                'item' => $indexId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'spring_exchange&'.$indexId,
                'value' => 1
            )
        ));

        if ($activityTreeExchangeSetting['trimmingId']) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
                'clientData' => array(
                    'tid' =>$activityTreeExchangeSetting['trimmingId'].':1|',
                    'item' => 'spring_exchange&'.$indexId,
                    'value' => 1
                )
            ));
        }

        if ($input) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
                'clientData' => array(
                    'tid' =>$input,
                    'item' => 'spring_exchange&'.$indexId,
                    'value' => 1
                )
            ));
        }

        $res['state'] = true;
        return $res;
    }

    /**
     * 更新水滴数量
     * @param $userId
     * @param $activityId
     * @param $number
     * @throws SzException
     */
    public function updateActivityTreeNum($userId,$activityId,$number) {
        /**
         * @var $activityTreeInfoList ActivityTreeInfoVoList
         * @var $activityTreeInfo ActivityTreeInfoVo
         */
        $activityTreeInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TREE_INFO);
        $activityTreeInfo = $activityTreeInfoList->getElement($activityId,false);
        if (!$activityTreeInfo) {
            $activityTreeInfo = new ActivityTreeInfoVo($userId,$activityId,[],[],0,0,0,0,0,true);
        }

        $activityTreeInfo->updateNoCalculated($number);

        if ( $activityTreeInfo->isInsert() && !SzUtility::checkArrayKey($activityId,  $activityTreeInfoList->getList())) {
            $activityTreeInfoList->addElement( $activityTreeInfo);
            $activityTreeInfoList->setElement($activityId, $activityTreeInfo);
        } else {
            $activityTreeInfoList->updateElement($activityId, $activityTreeInfo);
        }

        SzPersister::get()->setVoList($activityTreeInfoList);
        return;
    }

    /**
     * 获取活动id
     * @param $userId int
     * @return int
     */
    public function getActivityTreeIndexId($userId) {
        $serverTime = GameService::get()->getReqTime();
        $activityList = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, null, true);
        if (!$activityList) {
            return 0;
        }

        $userLevel = UserService::get()->getUserLevel($userId);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];

        foreach ($activityList as $activity) {
            $startTime = strtotime($activity[$platformPre.'TriggerTime']);
            $endTime = strtotime($activity[$platformPre.'EndTime']);
            $type = $activity['type'];
            if ($type == self::ActivityTree && $serverTime >= $startTime && $serverTime <= $endTime && $userLevel >= $activity['triggerLv']) {
                return $activity['indexId'];
            }
        }
        return 0;
    }

    /***********************************情人节活动*********************************************/
    /**
     * 活动信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityValentineInfo($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         * @var $activityValentineOrderList ActivityValentineOrderVoList
         * @var $activityValentineOrder ActivityValentineOrderVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,true);
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
            SzPersister::get()->setVoList($activityValentineInfoList);
        }

        $activityValentineOrderList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_ORDER);

        for ($i = 1; $i <= $activityValentineInfoSetting['orderNumber']; $i++) {
            $activityValentineOrder = $activityValentineOrderList->getElement($i,false);
            if (!$activityValentineOrder) {
                $orderInfo = $this->initValentineOrder();

                $productionId = array_rand($orderInfo['productionId']);
                $buildEntityId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_CONSUME,GameConst::ENTITY_TYPE_ITEM,$orderInfo['productionId'][$productionId]);
                $costItem = array(
                    $buildEntityId => $orderInfo['costItem']
                );

                $activityValentineOrder = new ActivityValentineOrderVo($userId,$i,$activityId,json_encode($costItem,true),json_encode($orderInfo['reward'],true),$orderInfo['loveNum'],$reqTime,true);
                $activityValentineOrderList->addElement($activityValentineOrder);
                $activityValentineOrderList->setElement($i,$activityValentineOrder);
            } else if ($activityValentineOrder->getIndexId() != $activityId) {
                $orderInfo = $this->initValentineOrder();

                $productionId = array_rand($orderInfo['productionId']);
                $buildEntityId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_CONSUME,GameConst::ENTITY_TYPE_ITEM,$orderInfo['productionId'][$productionId]);
                $costItem = array(
                    $buildEntityId => $orderInfo['costItem']
                );

                $activityValentineOrder->setIndexId($activityId);
                $activityValentineOrder->setCoolDown($reqTime);
                $activityValentineOrder->setCostItem($costItem);
                $activityValentineOrder->setReward($orderInfo['reward']);
                $activityValentineOrder->setLoveNum($orderInfo['loveNum']);
                $activityValentineOrderList->updateElement($i,$activityValentineOrder);
            }
        }
        SzPersister::get()->setVoList($activityValentineOrderList);
        return array(
            'activityValentineOrderList' => $activityValentineOrderList->toArray(),
            'activityValentineInfo' => $activityValentineInfo->toArray()
        );
    }

    /**
     * 提交订单
     * @param $userId
     * @param $activityId
     * @param $isGiveUp
     * @param $reqTime
     * @param $position
     * @return array
     * @throws SzException
     */
    public function activityValentineOrderReward($userId,$activityId,$position,$isGiveUp,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         * @var $activityValentineOrderList ActivityValentineOrderVoList
         * @var $activityValentineOrder ActivityValentineOrderVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,true);
        }

        $activityValentineOrderList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_ORDER);
        $activityValentineOrder = $activityValentineOrderList->getElement($position);

        if ($activityValentineOrder->getIndexId() != $activityId) {
            throw new SzException(90064);
        }

        if ($activityValentineOrder->getCoolDown() > $reqTime) {
            throw new SzException(90064);
        }

        if (!$isGiveUp) {
            $input = $output = '';
            foreach ($activityValentineOrder->getRawCostItem() as $entityId => $count) {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
                $input .= $entityId.':'.$count.'|';
            }
            CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,0,$input,'activityValentineOrderReward');//消耗资源上报

            foreach ($activityValentineOrder->getRawReward() as $entityId => $count) {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
                $output .= $entityId.':'.$count.'|';
            }
            CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,1,$output,'activityValentineOrderReward');//获得资源上报

            $activityValentineInfo->updateLoveNum($activityValentineOrder->getLoveNum());
            $activityValentineInfo->updateSurplusLoveNum($activityValentineOrder->getLoveNum());

            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                'clientData' => array(
                    'tid' => 'Module:valentine|action:order|',
                    'item' => 'valentine_order',
                    'value' => 1
                )
            ));

            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' =>$output,
                    'item' => 'valentine_order',
                    'value' => 1
                )
            ));

            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
                'clientData' => array(
                    'tid' =>$input,
                    'item' => 'valentine_order',
                    'value' => 1
                )
            ));
        }

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        $orderInfo = $this->initValentineOrder();

        $productionId = array_rand($orderInfo['productionId']);
        $buildEntityId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_CONSUME,GameConst::ENTITY_TYPE_ITEM,$orderInfo['productionId'][$productionId]);
        $costItem = array(
            $buildEntityId => $orderInfo['costItem']
        );

        $activityValentineOrder->setCoolDown($reqTime + $activityValentineInfoSetting['orderRefreshTime']);
        $activityValentineOrder->setCostItem($costItem);
        $activityValentineOrder->setReward($orderInfo['reward']);
        $activityValentineOrder->setLoveNum($orderInfo['loveNum']);

        $activityValentineOrderList->updateElement($position,$activityValentineOrder);
        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineOrderList);
        SzPersister::get()->setVoList($activityValentineInfoList);

        return array(
            'activityValentineOrder' => $activityValentineOrder->toArray(),
            'activityValentineInfo' => $activityValentineInfo->toArray()
        );
    }

    /**
     * 清除CD时间
     * @param $userId
     * @param $activityId
     * @param $position
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityValentineOrderRefresh($userId,$activityId,$position,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO, $activityId, true);
        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineOrderList ActivityValentineOrderVoList
         * @var $activityValentineOrder ActivityValentineOrderVo
         */

        $activityValentineOrderList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_ORDER);
        $activityValentineOrder = $activityValentineOrderList->getElement($position);

        if ($activityValentineOrder->getIndexId() != $activityId) {
            throw new SzException(90064);
        }

        $input = '';
        $useGold = 0;
        foreach ($activityValentineInfoSetting['orderCostItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $input .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,0,$input,'activityValentineOrderRefresh');//消耗资源上报

        $activityValentineOrder->setCoolDown($reqTime);
        $activityValentineOrderList->updateElement($position,$activityValentineOrder);
        SzPersister::get()->setVoList($activityValentineOrderList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:orderCD|',
                'item' => 'valentine_orderCD',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'valentine_orderCD',
                    'value' => $useGold
                )
            ));
        }

        return array(
            'activityValentineOrder' => $activityValentineOrder->toArray(),
        );
    }

    /**
     * 购买礼包
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineGiftPackBuy($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO, $activityId, true);

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,true);
        }

        if ($reqTime < $activityValentineInfo->getGiftPackRefreshTime()) {
            throw new SzException(90062);
        }

        $input = $output = '';
        $useGold = 0;
        foreach ($activityValentineInfoSetting['giftpackcostItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $input .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,0,$input,'activityValentineGiftPackBuy');//消耗资源上报

        foreach ($activityValentineInfoSetting['giftpackReward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,1,$output,'activityValentineGiftPackBuy');//获得资源上报

        $activityValentineInfo->updateSurplusLoveNum($activityValentineInfoSetting['giftpackloveNum']);
        $activityValentineInfo->updateLoveNum($activityValentineInfoSetting['giftpackloveNum']);
        $activityValentineInfo->setGiftPackRefreshTime($activityValentineInfoSetting['giftpackRefreshTime'] + $reqTime);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:gift|',
                'item' => 'valentine_gift',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'valentine_orderCD',
                    'value' => $useGold
                )
            ));
        }

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'valentine_gift',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 刷新
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineGiftPackRefresh($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,true);
        }

        // 扣除钻石
        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_CONSUME_MONEY, 50, true);
        CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,0,GameConst::ENTITY_ACTION_CONSUME_MONEY.':50|','activityValentineGiftPackRefresh');//消耗资源上报

        $activityValentineInfo->setGiftPackRefreshTime($reqTime);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:orderCD|',
                'item' => 'valentine_orderCD',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
            'clientData' => array(
                'item' => 'valentine_giftCD',
                'value' => 50
            )
        ));

        return true;
    }

    /**
     * 领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineGiftPackReward($userId,$activityId,$indexId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,true);
        }

        $info = $activityValentineInfo->getRawInfo();

        $info = $info ? $info : array();

        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        $activityValentineRewardSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_REWARD, $indexId, true);

        $number = $activityValentineRewardSetting['number'];
        if ($number > $activityValentineInfo->getLoveNum()) {
            throw new SzException(90062);
        }

        $output= '';
        foreach ($activityValentineRewardSetting['reward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999981,$userId,1,$output,'activityValentineGiftPackReward');//获得资源上报

        $info[] = $indexId;
        $activityValentineInfo->setInfo($info);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:valentine|action:exchange|',
                'item' => $indexId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'valentine_exchange&'.$indexId,
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 获取订单
     * @return array
     */
    public function initValentineOrder() {
        $activityValentineOrderSettings = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_ORDER, null, true);
        if (!$activityValentineOrderSettings) {
            return array();
        }

        $rate = array();
        foreach ($activityValentineOrderSettings as $activityValentineOrderSetting) {
            $rate[$activityValentineOrderSetting['id']] = $activityValentineOrderSetting['rate'];
        }

        $id = SzUtility::getRandomElementByProbability($rate);

        return $activityValentineOrderSettings[$id];
    }

    /***********************************女王节活动*********************************************/
    /**
     * 活动信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityValentineInfo1($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }
        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO1, $activityId, true);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        $rangeTime = $endTime - $startTime;

        //获取玩家数据
        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         * @var $activityValentineOrderList ActivityValentineOrderVoList
         * @var $activityValentineOrder ActivityValentineOrderVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if ($activityValentineInfo) {
            //获取玩家自己的活动时间
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0, $reqTime,$reqTime + $rangeTime,true);
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
            SzPersister::get()->setVoList($activityValentineInfoList);
        }

        $activityValentineOrderList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_ORDER);

        for ($i = 1; $i <= $activityValentineInfoSetting['orderNumber']; $i++) {
            $activityValentineOrder = $activityValentineOrderList->getElement($i,false);
            if (!$activityValentineOrder) {
                $orderInfo = $this->initValentineOrder1($userId);

                $buildEntityId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_CONSUME,GameConst::ENTITY_TYPE_ITEM,$orderInfo['flowerId']);
                $costItem = array(
                    $buildEntityId => 100
                );

                $activityValentineOrder = new ActivityValentineOrderVo($userId,$i,$activityId,json_encode($costItem,true),json_encode($orderInfo['reward'],true),$orderInfo['loveNum'],$reqTime,true);
                $activityValentineOrderList->addElement($activityValentineOrder);
                $activityValentineOrderList->setElement($i,$activityValentineOrder);
            } else if ($activityValentineOrder->getIndexId() != $activityId) {
                $orderInfo = $this->initValentineOrder1($userId);

                $buildEntityId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_CONSUME,GameConst::ENTITY_TYPE_ITEM,$orderInfo['flowerId']);
                $costItem = array(
                    $buildEntityId => 100
                );

                $activityValentineOrder->setIndexId($activityId);
                $activityValentineOrder->setCoolDown($reqTime);
                $activityValentineOrder->setCostItem($costItem);
                $activityValentineOrder->setReward($orderInfo['reward']);
                $activityValentineOrder->setLoveNum($orderInfo['loveNum']);
                $activityValentineOrderList->updateElement($i,$activityValentineOrder);
            }
        }
        SzPersister::get()->setVoList($activityValentineOrderList);

        return array(
            'activityValentineOrderList' => $activityValentineOrderList->toArray(),
            'activityValentineInfo' => $activityValentineInfo->toArray()
        );
    }

    /**
     * 提交订单
     * @param $userId
     * @param $activityId
     * @param $isGiveUp
     * @param $reqTime
     * @param $position
     * @return array
     * @throws SzException
     */
    public function activityValentineOrderReward1($userId,$activityId,$position,$isGiveUp,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO1, $activityId, true);
        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        $rangeTime = $endTime - $startTime;
        if ($activityValentineInfo){
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineOrderList ActivityValentineOrderVoList
         * @var $activityValentineOrder ActivityValentineOrderVo
         */
        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,$reqTime,$reqTime + $rangeTime,true);
        }

        $activityValentineOrderList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_ORDER);
        $activityValentineOrder = $activityValentineOrderList->getElement($position);

        if ($activityValentineOrder->getIndexId() != $activityId) {
            throw new SzException(90064);
        }

        if ($activityValentineOrder->getCoolDown() > $reqTime) {
            throw new SzException(90064);
        }

        if (!$isGiveUp) {
            $input = $output = '';
            foreach ($activityValentineOrder->getRawCostItem() as $entityId => $count) {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
                $input .= $entityId.':'.$count.'|';
            }
            CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,0,$input,'activityValentineOrderReward1');//消耗资源上报

            foreach ($activityValentineOrder->getRawReward() as $entityId => $count) {
                GameService::get()->handleEntity($userId, $entityId, $count, true);
                $output .= $entityId.':'.$count.'|';
            }
            CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,1,$output,'activityValentineOrderReward1');//获得资源上报

            $activityValentineInfo->updateSurplusLoveNum($activityValentineOrder->getLoveNum());
            $activityValentineInfo->updateLoveNum($activityValentineOrder->getLoveNum());

            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                'clientData' => array(
                    'tid' => 'Module:queen|action:order|',
                    'item' => 'queen_order',
                    'value' => 1
                )
            ));

            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
                'clientData' => array(
                    'tid' =>$output,
                    'item' => 'queen_order',
                    'value' => 1
                )
            ));

            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_INPUT, array(
                'clientData' => array(
                    'tid' =>$input,
                    'item' => 'queen_order',
                    'value' => 1
                )
            ));
        }

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        $orderInfo = $this->initValentineOrder1($userId);

        $buildEntityId = EntityService::get()->buildEntityId(GameConst::ENTITY_ACTION_CONSUME,GameConst::ENTITY_TYPE_ITEM,$orderInfo['flowerId']);
        $costItem = array(
            $buildEntityId => 100
        );

        $activityValentineOrder->setCoolDown($reqTime + $activityValentineInfoSetting['orderRefreshTime']);
        $activityValentineOrder->setCostItem($costItem);
        $activityValentineOrder->setReward($orderInfo['reward']);
        $activityValentineOrder->setLoveNum($orderInfo['loveNum']);

        $activityValentineOrderList->updateElement($position,$activityValentineOrder);
        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineOrderList);
        SzPersister::get()->setVoList($activityValentineInfoList);

        return array(
            'activityValentineOrder' => $activityValentineOrder->toArray(),
            'activityValentineInfo' => $activityValentineInfo->toArray()
        );
    }

    /**
     * 清除CD时间
     * @param $userId
     * @param $activityId
     * @param $position
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityValentineOrderRefresh1($userId,$activityId,$position,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO1, $activityId, true);
        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        if ($activityValentineInfo){
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        /**
         * @var $activityValentineOrderList ActivityValentineOrderVoList
         * @var $activityValentineOrder ActivityValentineOrderVo
         */

        $activityValentineOrderList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_ORDER);
        $activityValentineOrder = $activityValentineOrderList->getElement($position);

        if ($activityValentineOrder->getIndexId() != $activityId) {
            throw new SzException(90064);
        }

        $input = '';
        $useGold = 0;
        foreach ($activityValentineInfoSetting['orderCostItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $input .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,0,$input,'activityValentineOrderRefresh1');//消耗资源上报

        $activityValentineOrder->setCoolDown($reqTime);
        $activityValentineOrderList->updateElement($position,$activityValentineOrder);
        SzPersister::get()->setVoList($activityValentineOrderList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:queen|action:orderCD|',
                'item' => 'queen_orderCD',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'queen_orderCD',
                    'value' => $useGold
                )
            ));
        }

        return array(
            'activityValentineOrder' => $activityValentineOrder->toArray(),
        );
    }

    /**
     * 购买礼包
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineGiftPackBuy1($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);

        $activityValentineInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_INFO1, $activityId, true);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        $rangeTime = $endTime - $startTime;

        if ($activityValentineInfo){
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0, $reqTime, $reqTime + $rangeTime,true);
        }

        if ($reqTime < $activityValentineInfo->getGiftPackRefreshTime()) {
            throw new SzException(90062);
        }

        $input = $output = '';
        $useGold = 0;
        foreach ($activityValentineInfoSetting['giftpackcostItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $input .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,0,$input,'activityValentineGiftPackBuy1');//消耗资源上报

        foreach ($activityValentineInfoSetting['giftpackReward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,1,$output,'activityValentineGiftPackBuy1');//获得资源上报
        
        $activityValentineInfo->updateSurplusLoveNum($activityValentineInfoSetting['giftpackloveNum']);
        $activityValentineInfo->updateLoveNum($activityValentineInfoSetting['giftpackloveNum']);
        $activityValentineInfo->setGiftPackRefreshTime($activityValentineInfoSetting['giftpackRefreshTime'] + $reqTime);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:queen|action:gift|',
                'item' => 'queen_gift',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'queen_gift',
                    'value' => $useGold
                )
            ));
        }

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'valentine_gift',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 刷新
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineGiftPackRefresh1($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        $rangeTime = $endTime - $startTime;
        if ($activityValentineInfo){
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,$reqTime,$reqTime + $rangeTime,true);
        }

        // 扣除钻石
        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_CONSUME_MONEY, 50, true);
        CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,0,GameConst::ENTITY_ACTION_CONSUME_MONEY.':50|','activityValentineGiftPackRefresh1');//消耗资源上报

        $activityValentineInfo->setGiftPackRefreshTime($reqTime);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:queen|action:giftCD|',
                'item' => 'queen_giftCD',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
            'clientData' => array(
                'item' => 'queen_giftCD',
                'value' => 50
            )
        ));

        return true;
    }

    /**
     * 领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineGiftPackReward1($userId,$activityId,$indexId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        $rangeTime = $endTime - $startTime;
        if ($activityValentineInfo){
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,$reqTime, $reqTime + $rangeTime,true);
        }

        $info = $activityValentineInfo->getRawInfo();

        $info = $info ? $info : array();

        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        $activityValentineRewardSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_VALENTINE_REWARD1, $indexId, true);

        $number = $activityValentineRewardSetting['number'];
        if ($number > $activityValentineInfo->getLoveNum()) {
            throw new SzException(90062);
        }

        $output= '';
        foreach ($activityValentineRewardSetting['reward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,1,$output,'activityValentineGiftPackReward1');//获得资源上报

        $info[] = $indexId;
        $activityValentineInfo->setInfo($info);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:queen|action:reward|',
                'item' => 'queen_reward&'.$indexId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'queen_reward&'.$indexId,
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 兑换
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityValentineExchange1($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activity[$platformPre.'TriggerTime']);
        $endTime = strtotime($activity[$platformPre.'EndTime']);
        $rangeTime = $endTime - $startTime;

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        /**
         * @var $activityValentineInfoList ActivityValentineInfoVoList
         * @var $activityValentineInfo ActivityValentineInfoVo
         */
        $activityValentineInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_VALENTINE_INFO);
        $activityValentineInfo = $activityValentineInfoList->getElement($activityId,false);
        if ($activityValentineInfo){
            $startTime = $activityValentineInfo->getCreateTime();
            $endTime = $activityValentineInfo->getEndTime();
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityValentine1) {
            throw new SzException(90005);
        }

        if (!$activityValentineInfo) {
            $activityValentineInfo = new ActivityValentineInfoVo($userId,$activityId,0,[],$reqTime,0,$reqTime,$reqTime + $rangeTime,true);
        }

        if (!$activityValentineInfo->getSurplusLoveNum()) {
            throw new SzException(90062);
        }
        $count =$activityValentineInfo->getSurplusLoveNum() * 1000;
        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_GET_TOKEN , $count, true);
        CommonFunctionService::get()->reportResourceUseDetails(99999975,$userId,1,GameConst::ENTITY_ACTION_GET_TOKEN.':'.$count.'|','activityValentineExchange1');//获得资源上报

        $activityValentineInfo->setSurplusLoveNum(0);

        if ( $activityValentineInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityValentineInfoList->getList())) {
            $activityValentineInfoList->addElement($activityValentineInfo);
            $activityValentineInfoList->setElement($activityId,$activityValentineInfo);
        } else {
            $activityValentineInfoList->updateElement($activityId, $activityValentineInfo);
        }

        SzPersister::get()->setVoList($activityValentineInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:queen|action:gold|',
                'item' => 'queen_gold',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>GameConst::ENTITY_ACTION_GET_TOKEN .':'.$count.'|',
                'item' => 'queen_gold',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * @param $userId
     * @return array
     * @throws SzException
     */
    public function initValentineOrder1($userId) {
        $unlockFlowers = SeedService::get()->getUnlockFlowerList($userId);
        $key = array_rand($unlockFlowers);
        $flowerId = $unlockFlowers[$key];
        $orderRewardSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_ORDER_REWARD, $flowerId, true);
        return array(
            'flowerId' => $flowerId,
            'reward' => array(
                GameConst::ENTITY_ACTION_GET_TOKEN => $orderRewardSetting['gold'] * 3 * 100
            ),
            'loveNum' => 1
        );
    }

    /***********************************个人目标活动*********************************************/
    /**
     * 获取信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityPersonalGoalsInfo($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityPersonalGoals) {
            throw new SzException(90005);
        }

        /**
         * @var $activityPersonalGoalsInfoList ActivityPersonalGoalsInfoVoList
         * @var $activityPersonalGoalsInfo ActivityPersonalGoalsInfoVo
         */
        $activityPersonalGoalsInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PERSONAL_GOALS_INFO);
        $activityPersonalGoalsInfo = $activityPersonalGoalsInfoList->getElement($activityId,false);
        if (!$activityPersonalGoalsInfo) {
            $activityPersonalGoalsInfo = new ActivityPersonalGoalsInfoVo($userId,$activityId,[], [], 0, 0, 0, 0, $reqTime,true);
            $activityPersonalGoalsInfoList->addElement($activityPersonalGoalsInfo);
            $activityPersonalGoalsInfoList->setElement($activityId,$activityPersonalGoalsInfo);
            SzPersister::get()->setVoList($activityPersonalGoalsInfoList);
        }

        return $activityPersonalGoalsInfo->toArray();
    }

    /**
     * 购买礼包
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityPersonalGoalsBuy($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityPersonalGoals) {
            throw new SzException(90005);
        }

        /**
         * @var $activityPersonalGoalsInfoList ActivityPersonalGoalsInfoVoList
         * @var $activityPersonalGoalsInfo ActivityPersonalGoalsInfoVo
         */
        $activityPersonalGoalsInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PERSONAL_GOALS_INFO);
        $activityPersonalGoalsInfo = $activityPersonalGoalsInfoList->getElement($activityId,false);

        if (!$activityPersonalGoalsInfo) {
            $activityPersonalGoalsInfo = new ActivityPersonalGoalsInfoVo($userId,$activityId,[], [], 0, 0, 0, 0, $reqTime,true);
        }

        if ($reqTime < $activityPersonalGoalsInfo->getGiftPackRefreshTime()) {
            throw new SzException(90062);
        }

        $activityPersonalGoalsInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_PERSONAL_GOALS_INFO, $activityId, true);

        $input = $output = '';
        $useGold = 0;
        foreach ($activityPersonalGoalsInfoSetting['giftPackCostItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $input .= $entityId.':'.$count.'|';
            if ($entityId == GameConst::ENTITY_ACTION_CONSUME_MONEY) {
                $useGold += $count;
            }
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999973,$userId,0,$input,'activityPersonalGoalsBuy');//消耗资源上报

        foreach ($activityPersonalGoalsInfoSetting['giftpackReward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999973,$userId,1,$output,'activityPersonalGoalsBuy');//获得资源上报

        $activityPersonalGoalsInfo->updateTotalNum($activityPersonalGoalsInfoSetting['giftpackloveNum']);
        $activityPersonalGoalsInfo->setGiftPackRefreshTime($activityPersonalGoalsInfoSetting['giftpackRefreshTime'] + $reqTime);

        if ($activityPersonalGoalsInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityPersonalGoalsInfoList->getList())) {
            $activityPersonalGoalsInfoList->addElement($activityPersonalGoalsInfo);
            $activityPersonalGoalsInfoList->setElement($activityId,$activityPersonalGoalsInfo);
        } else {
            $activityPersonalGoalsInfoList->updateElement($activityId, $activityPersonalGoalsInfo);
        }

        SzPersister::get()->setVoList($activityPersonalGoalsInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:target|action:get|',
                'item' => $activityPersonalGoalsInfoSetting['giftpackloveNum'],
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:target|action:buy|',
                'item' => 'target_buy',
                'value' => 1
            )
        ));

        if ($useGold) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
                'clientData' => array(
                    'item' => 'target_buy',
                    'value' => $useGold
                )
            ));
        }

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'target_buy',
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 刷新
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityPersonalGoalsRefresh($userId,$activityId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityPersonalGoals) {
            throw new SzException(90005);
        }

        /**
         * @var $activityPersonalGoalsInfoList ActivityPersonalGoalsInfoVoList
         * @var $activityPersonalGoalsInfo ActivityPersonalGoalsInfoVo
         */
        $activityPersonalGoalsInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PERSONAL_GOALS_INFO);
        $activityPersonalGoalsInfo = $activityPersonalGoalsInfoList->getElement($activityId,false);

        if (!$activityPersonalGoalsInfo) {
            $activityPersonalGoalsInfo = new ActivityPersonalGoalsInfoVo($userId,$activityId,[], [], 0, 0, 0, 0, $reqTime,true);
        }

        if ($reqTime >= $activityPersonalGoalsInfo->getGiftPackRefreshTime()) {
            return true;
        }

        $activityPersonalGoalsInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_PERSONAL_GOALS_INFO, $activityId, true);


        $useGold =  $activityPersonalGoalsInfoSetting['giftPackRefreshCostItem'];

        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_CONSUME_MONEY, $activityPersonalGoalsInfoSetting['giftPackRefreshCostItem'], true);
        CommonFunctionService::get()->reportResourceUseDetails(99999973,$userId,0,GameConst::ENTITY_ACTION_CONSUME_MONEY.':'.$activityPersonalGoalsInfoSetting['giftPackRefreshCostItem'].'|','activityPersonalGoalsRefresh');//消耗资源上报

        $activityPersonalGoalsInfo->setGiftPackRefreshTime($reqTime);

        if ($activityPersonalGoalsInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityPersonalGoalsInfoList->getList())) {
            $activityPersonalGoalsInfoList->addElement($activityPersonalGoalsInfo);
            $activityPersonalGoalsInfoList->setElement($activityId,$activityPersonalGoalsInfo);
        } else {
            $activityPersonalGoalsInfoList->updateElement($activityId, $activityPersonalGoalsInfo);
        }

        SzPersister::get()->setVoList($activityPersonalGoalsInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:target|action:buyCD|',
                'item' => 'target_buyCD',
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USE_GOLD, array(
            'clientData' => array(
                'item' => 'target_buyCD',
                'value' => $useGold
            )
        ));

        return true;
    }

    /**
     * 领奖
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityPersonalGoalsReward($userId,$activityId,$indexId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityPersonalGoals) {
            throw new SzException(90005);
        }

        /**
         * @var $activityPersonalGoalsInfoList ActivityPersonalGoalsInfoVoList
         * @var $activityPersonalGoalsInfo ActivityPersonalGoalsInfoVo
         */
        $activityPersonalGoalsInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PERSONAL_GOALS_INFO);
        $activityPersonalGoalsInfo = $activityPersonalGoalsInfoList->getElement($activityId,false);

        $info = $activityPersonalGoalsInfo->getRawInfo();

        $info = $info ? $info : array();

        if (in_array($indexId,$info)) {
            throw new SzException(90007);
        }

        $activityPersonalGoalsRewardSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_PERSONAL_GOALS_REWARD, $indexId, true);

        if ($activityId != $activityPersonalGoalsRewardSetting['activityId']) {
            return false;
        }

        $number = $activityPersonalGoalsRewardSetting['number'];

        if ($number > $activityPersonalGoalsInfo->getTotalNum()) {
            throw new SzException(90062);
        }

        $output= '';
        foreach ($activityPersonalGoalsRewardSetting['reward'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999973,$userId,1,$output,'activityPersonalGoalsReward');//获得资源上报

        $info[] = $indexId;
        $activityPersonalGoalsInfo->setInfo($info);

        if ($activityPersonalGoalsInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityPersonalGoalsInfoList->getList())) {
            $activityPersonalGoalsInfoList->addElement($activityPersonalGoalsInfo);
            $activityPersonalGoalsInfoList->setElement($activityId,$activityPersonalGoalsInfo);
        } else {
            $activityPersonalGoalsInfoList->updateElement($activityId, $activityPersonalGoalsInfo);
        }

        SzPersister::get()->setVoList($activityPersonalGoalsInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:target|action:reward|',
                'item' => 'target_reward&'.$indexId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' =>$output,
                'item' => 'target_reward&'.$indexId,
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 兑换
     * @param $userId
     * @param $activityId
     * @param $indexId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function activityPersonalGoalsExchange($userId,$activityId,$indexId,$reqTime) {
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);

        $userLevel = UserService::get()->getUserLevel($userId);
        if ($userLevel < $activity['triggerLv']) {
            throw new SzException(90068);
        }

        $startTime = $activity['startTime'];
        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }

        $endTime = $activity['endTime'];
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

        if ($activity['type'] != self::ActivityPersonalGoals) {
            throw new SzException(90005);
        }

        /**
         * @var $activityPersonalGoalsInfoList ActivityPersonalGoalsInfoVoList
         * @var $activityPersonalGoalsInfo ActivityPersonalGoalsInfoVo
         */
        $activityPersonalGoalsInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PERSONAL_GOALS_INFO);
        $activityPersonalGoalsInfo = $activityPersonalGoalsInfoList->getElement($activityId);

        $activityPersonalGoalsExchangeSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_PERSONAL_GOALS_EXCHANGE, $indexId, true);

        if ($activityId != $activityPersonalGoalsExchangeSetting['activityId']) {
            return false;
        }

        $info = array();
        if ($activityPersonalGoalsExchangeSetting['type']) {
            $info = $activityPersonalGoalsInfo->getRawExchangeInfo();
            $info = $info ? $info : array();
            $exchangeNum = isset($info[$indexId]) ?  $info[$indexId] : 0;
            if ($activityPersonalGoalsExchangeSetting['type'] <= $exchangeNum) {
                throw new SzException(90070);
            }
            if($activityPersonalGoalsExchangeSetting['costItemNum'] > ($activityPersonalGoalsInfo->getTotalNum() - $activityPersonalGoalsInfo->getUseNum())) {
                throw new SzException(90069);
            }
        }

        if($activityPersonalGoalsExchangeSetting['costItemNum'] > ($activityPersonalGoalsInfo->getTotalNum() - $activityPersonalGoalsInfo->getUseNum())) {
            throw new SzException(90069);
        }

        $output= '';
        foreach ($activityPersonalGoalsExchangeSetting['getItem'] as $entityId => $count) {
            GameService::get()->handleEntity($userId, $entityId, $count, true);
            $output .= $entityId.':'.$count.'|';
        }
        CommonFunctionService::get()->reportResourceUseDetails(99999973,$userId,1,$output,'activityPersonalGoalsExchange');//获得资源上报

        if ($activityPersonalGoalsExchangeSetting['type']) {
            $info[$indexId] += 1;
            $activityPersonalGoalsInfo->setExchangeInfo($info);
        }
        $activityPersonalGoalsInfo->updateUseNum($activityPersonalGoalsExchangeSetting['costItemNum']);
        $activityPersonalGoalsInfoList->updateElement($activityId,$activityPersonalGoalsInfo);
        SzPersister::get()->setVoList($activityPersonalGoalsInfoList);

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
            'clientData' => array(
                'tid' => 'Module:target|action:exchange|',
                'item' => $indexId,
                'value' => 1
            )
        ));

        StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_RESOURCE_OUTPUT, array(
            'clientData' => array(
                'tid' => 'target_exchange',
                'item' => $output,
                'value' => 1
            )
        ));

        return true;
    }

    /**
     * 获取活动id
     * @param $userId
     * @param $reqTime
     * @return int
     */
    public function getActivityPersonalGoalsIndexId($userId,$reqTime) {
        $serverTime = GameService::get()->getReqTime();
        $activityList = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, null, true);
        if (!$activityList) {
            return 0;
        }

        $userLevel = UserService::get()->getUserLevel($userId);

        foreach ($activityList as $activity) {
            $startTime = $activity['startTime'];
            $endTime = $activity['endTime'];
            $type = $activity['type'];
            if ($type == self::ActivityPersonalGoals && $serverTime >= $startTime && $serverTime <= $endTime && $userLevel >= $activity['triggerLv']) {
                return $activity['indexId'];
            }
        }

        return 0;
    }

    /**
     * 更新数据
     * @param $userId
     * @param $activityId
     * @param $number
     * @param $isWater
     * @throws SzException
     */
    public function updateActivityPersonalGoalsNum($userId,$activityId,$number,$isWater,$isFlower=false) {
        /**
         * @var $activityPersonalGoalsInfoList ActivityPersonalGoalsInfoVoList
         * @var $activityPersonalGoalsInfo ActivityPersonalGoalsInfoVo
         */
        $activityPersonalGoalsInfoList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_PERSONAL_GOALS_INFO);
        $activityPersonalGoalsInfo = $activityPersonalGoalsInfoList->getElement($activityId,false);

        if (!$activityPersonalGoalsInfo) {
            $activityPersonalGoalsInfo = new ActivityPersonalGoalsInfoVo($userId,$activityId,[], [], 0, 0, 0, 0, GameService::get()->getReqTime(),true);
        }

        $activityPersonalGoalsInfoSetting = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_PERSONAL_GOALS_INFO, $activityId, true,false);
        if (!$activityPersonalGoalsInfoSetting) {
            return;
        }
        $waterNum = $activityPersonalGoalsInfoSetting['waterNum'];
        $flowerBasketNum = $activityPersonalGoalsInfoSetting['flowerBasketNum'];
        $addNum = 0;
        if ($isWater && $waterNum && $flowerBasketNum == 0) {
            $noUsedWater = $activityPersonalGoalsInfo->getNoUsedWater();
            $noUsedWater += $number;

            $surplusNoUsedWater = $noUsedWater;
            if ($noUsedWater >= $waterNum) {
                $add = intval($noUsedWater / $waterNum);
                $surplusNoUsedWater = $noUsedWater % $waterNum;
                $activityPersonalGoalsInfo->updateTotalNum($add);
                $addNum += $add;
            }
            $activityPersonalGoalsInfo->setNoUsedWater($surplusNoUsedWater);
        }

        if (!$isWater && $flowerBasketNum && $waterNum == 0) {
            $noUsedFlowerBasket = $activityPersonalGoalsInfo->getNoUsedFlowerBasket();
            $noUsedFlowerBasket += $number;

            $surplusNoUsedFlowerBasket = $noUsedFlowerBasket;
            if ($noUsedFlowerBasket >= $flowerBasketNum) {
                $add = intval($noUsedFlowerBasket / $flowerBasketNum);
                $surplusNoUsedFlowerBasket = $noUsedFlowerBasket % $flowerBasketNum;
                $activityPersonalGoalsInfo->updateTotalNum($add);
                $addNum += $add;
            }
            $activityPersonalGoalsInfo->setNoUsedFlowerBasket($surplusNoUsedFlowerBasket);
        }

        if (!$isWater && $waterNum == $flowerBasketNum && $waterNum == 0 && $isFlower) {
            $addActivityNum = $activityPersonalGoalsInfo->getTotalNum();
            $activityPersonalGoalsInfo->setTotalNum($addActivityNum + $number);
        }

        if ($activityPersonalGoalsInfo->isInsert() && !SzUtility::checkArrayKey($activityId, $activityPersonalGoalsInfoList->getList())) {
            $activityPersonalGoalsInfoList->addElement($activityPersonalGoalsInfo);
            $activityPersonalGoalsInfoList->setElement($activityId,$activityPersonalGoalsInfo);
        } else {
            $activityPersonalGoalsInfoList->updateElement($activityId, $activityPersonalGoalsInfo);
        }

        SzPersister::get()->setVoList($activityPersonalGoalsInfoList);

        if ($addNum) {
            StatisticsService::get()->saveLog($userId, GameConst::LOG_TYPE_USER_ORBIT, array(
                'clientData' => array(
                    'tid' => 'Module:target|action:get|',
                    'item' => $addNum,
                    'value' => 1
                )
            ));
        }

        return;
    }

    /***********************************儿童节活动*********************************************/
    /**
     * 获取公共信息
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return array
     * @throws SzException
     */
    public function activityCommonDataInfo($userId,$activityId,$reqTime) {
        /**
         * 获取目标玩家数据
         * @var $activityCommonDataList ActivityCommonDataVoList
         * @var $activityCommonData ActivityCommonDataVo
         */
        //获取活动配置
        $activityConf = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $activityCommonDataList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_COMMON);
        $activityCommonData = $activityCommonDataList->getElement($activityId,false);

        if ($activityCommonData){
            $checkStart = $activityCommonData->getCreateTime();
            $checkEnd = $activityCommonData->getEndTime();
            $this->checkActivityOpen($activityConf,2,$reqTime,$checkStart,$checkEnd);
        }else{
            $this->checkActivityOpen($activityConf,1,$reqTime,0,0,$userId);
        }

        //获取玩家平台数据
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];

        $interval = strtotime($activityConf[$platformPre.'EndTime']) - strtotime($activityConf[$platformPre.'TriggerTime']);

        //获取玩家活动公共数据模块
        $surplus = 0;
        $totalPoint = 0;
        $reward = array();

        $activityCommonDatas = $activityCommonDataList->toArray();
        $isCreate = false;
        foreach ($activityCommonDatas as $aid=>$data){
            if ($activityId == $data['activityId']){
                $isCreate = true;
                $surplus =  $data['totalPoint'] - $data['usePoint'];
                $totalPoint = $data['totalPoint'];
                if ($data['rewardInfo'] == 'null'){
                    $reward = array();
                }else{
                    $getReward = str_replace("null:", "", $data['rewardInfo']);
                    $reward = explode(':',(string)str_replace("\"", "", $getReward));
                }

                break;
            }
        }

        if (!$isCreate){
            //进行公共活动创建
            if (!$activityCommonData){
                $activityCommonData = new ActivityCommonDataVo(
                    $userId, // userId
                    $activityId, //$activityId
                    0, // $usePoint
                    0, // $totalPoint
                    '',//$rewardInfo
                    $reqTime,//$createTime
                    (($reqTime + $interval) == $reqTime) ? $activityConf['endTime'] : ($reqTime + $interval),//$endTime
                    true
                );
            }

            if ($activityCommonData->isInsert() && !SzUtility::checkArrayKey($activityId, $activityCommonDataList->getList())) {
                $activityCommonDataList->addElement($activityCommonData);
                $activityCommonDataList->setElement($activityId,$activityCommonData);
            }
        }

        SzPersister::get()->setVoList($activityCommonDataList);
        //获取玩家任务数据
        $taskData = ActivityTaskService::get()->getActivityTaskInfo($userId,$activityId,$reqTime);

        return array(
            'surplus' => $surplus,
            'total' => $totalPoint,
            'getReward' => $reward,
            'task' => $taskData,
            'activity' => $activityCommonData->toArray()['endTime']
        );
    }

    /**
     * 清理活动数据
     * @param $userId
     * @param $activityId
     * @param $reqTime
     * @return bool
     * @throws SzException
     */
    public function clearActivityData($userId,$activityId,$reqTime) {
        $activityConf = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $serverTime = GameService::get()->getReqTime();

        //获取玩家平台数据
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activityConf[$platformPre.'TriggerTime']);
        $endTime = strtotime($activityConf[$platformPre.'EndTime']);

        /**
         * 获取目标玩家数据
         * @var $activityCommonDataList ActivityCommonDataVoList
         * @var $activityCommonData ActivityCommonDataVo
         */
        $activityCommonDataList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_COMMON);
        $activityCommonData = $activityCommonDataList->getElement($activityId,false);
        $mineStartTime = $activityCommonData ? $activityCommonData->getCreateTime() : $startTime;
        $mineEndTime = $activityCommonData ? $activityCommonData->getEndTime() : $endTime;
        if (!$activityCommonData && ($mineStartTime > $reqTime || $mineEndTime <= $reqTime)) {
            //进行数据清理
            $activityCommonDatas = $activityCommonDataList->toArray();
            if (!empty($activityCommonDatas)){
                foreach ($activityCommonDatas as $aid=>$data){
                    if ($activityId == $data['activityId']){
                        $activityCommonDataList->deleteElement($aid);
                        SzPersister::get()->setVoList($activityCommonDataList);
                    }
                }
            }

            $taskDataList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TASK);
            $taskDatas = $taskDataList->toArray();
            if (!empty($taskDatas)){
                foreach ($taskDatas as $position=>$data){
                    if ($activityId == $data['activityId']){
                        $taskDataList->deleteElement($position);
                        SzPersister::get()->setVoList($taskDataList);
                    }
                }
            }
        }

        return true;
    }

    /**
     * 获取活动ID和任务档位
     * @param $userId
     * @param $taskId
     * @return array
     * @throws SzException
     */
    public function getActivityIdAndPosition($userId,$taskId){
        $taskConf = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_TASK, $taskId, true,false);
        if (empty($taskConf)){
            return array();
        }
        $activityConf = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $taskConf['activityId'], true,false);
        if (empty($activityConf)){
            return array();
        }
        $serverTime = GameService::get()->getReqTime();
        $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
        $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $startTime = strtotime($activityConf[$platformPre.'TriggerTime']);
        $endTime = strtotime($activityConf[$platformPre.'EndTime']);
        if ($serverTime > $endTime + 15*SzTime::HOURS24){
            return array();
        }

        /**
         * 获取目标玩家数据
         * @var $activityCommonDataList ActivityCommonDataVoList
         * @var $activityCommonData ActivityCommonDataVo
         */
        //验证活动是否开启
        $activityCommonDataList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_COMMON);
        $activityCommonData = $activityCommonDataList->getElement($taskConf['activityId'],false);
        if ($activityCommonData){
            $startTime = $activityCommonData->getCreateTime();
            $endTime = $activityCommonData->getEndTime();
        }

        if ($startTime > $serverTime || $endTime <= $serverTime) {
            return array();
        }
        $activityCommonDatas = $activityCommonDataList->toArray();
        if (empty($activityCommonDatas[$taskConf['activityId']])){
            return array();
            //创建活动数据和任务数据
//            $startCreateData = $this->activityCommonDataInfo($userId,$taskConf['activityId'],$serverTime);
//            return array('aid' => $taskConf['activityId'],'position'=>$startCreateData['task'][0]['position']);
        }
        $taskDataList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_ACTIVITY_TASK);
        $taskDatas = $taskDataList->toArray();
        if (empty($taskDatas)){
            return array();
//            $taskData = ActivityTaskService::get()->getActivityTaskInfo($userId,$taskConf['activityId'],$serverTime);
//            return array('aid' => $taskConf['activityId'],'position'=>$taskData['task'][0]['position']);
        }
        //数据已经创建
        foreach ($taskDatas as $position=>$data){
            if ($data['activityId'] == $taskConf['activityId'] && $data['taskType'] == $taskId){
                $position = $data['position'];
                return array('aid' => $taskConf['activityId'],'position'=>$position);
            }
        }

        return array();
    }

    //随机任务
    public function randTaskId($oldTaskId=0){
        //随机任务ID
        $constTaskTypeArr = array(GameConst::ACTIVITY_TASK_1,GameConst::ACTIVITY_TASK_2,GameConst::ACTIVITY_TASK_3,GameConst::ACTIVITY_TASK_4,GameConst::ACTIVITY_TASK_5);
        if ($oldTaskId){
            unset($constTaskTypeArr[$oldTaskId-1]);
        }

        $taskKey = array_rand($constTaskTypeArr);
        $taskId = $constTaskTypeArr[$taskKey];

        return $taskId;
    }

    //权重随机品质
    public function randWeightQuality(){
        $qualityConfs = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_ACTIVITY_TASK_QUALITY, null, true);
        if (empty($qualityConfs)){
            throw new SzException(90080);
        }

        $quality = 1;
        $tempWeigh = array();
        for($i=1;$i<=count($qualityConfs);$i++){
            $tempWeigh[] = array('quality'=>$qualityConfs[$i]['quality'],'weight'=>$qualityConfs[$i]['weight']);
        }

        if (!empty($tempWeigh)){
            $quality = ($this->useWeightRand($tempWeigh))['quality'];
        }

        return $quality;
    }

    //权重随机
    public function useWeightRand($weighArr){
        $weight = 0;
        $temp = array();
        foreach ($weighArr as $data){
            $weight += $data['weight'];
            for ($i=0;$i<$data['weight'];$i++){
                $temp[] = $data;
            }
        }
        $use = rand(0, $weight-1);
        return $temp[$use];
    }

    //检测活动开启
    public function checkActivityOpen($activityConf,$type,$serverTime,$mineStart=0,$mineEnd=0,$userId=0){
//        $serverTime = GameService::get()->getReqTime();
        $startTime = $activityConf['startTime'];
        $endTime = $activityConf['endTime'];
        if ($type == 2){
            $startTime = $mineStart;
            $endTime = $mineEnd;
        }

        if ($type == 1){
            //获取玩家平台数据
            $platform = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_PLATFORM);
            $platformPre = GameConst::PLATFORM_TIME_ARRAY[$platform];

            $startTime = strtotime($activityConf[$platformPre.'TriggerTime']);
            $endTime = strtotime($activityConf[$platformPre.'EndTime']);
        }

        if ($startTime > $serverTime) {
            throw new SzException(90001);
        }

        if ($endTime < $serverTime) {
            throw new SzException(90002);
        }
        if ($activityConf['type'] != self::ActivityChildren) {
            throw new SzException(90005);
        }
    }

    /**
     * 新检测活动开启
     * @param $activityId
     * @param $platform
     * @param $reqTime
     * @return mixed
     * @throws SzException
     */
    public function currencyCheckActivityRangeTime($activityId, $platform, $reqTime){
        $platform = GameConst::PLATFORM_TIME_ARRAY[$platform];
        $activity = SzConfig::get()->loadAppConfig(GameConst::CONFIG_GAME_EVENT, $activityId, true);
        $startTime = strtotime($activity[$platform.'TriggerTime']);
        $endTime = strtotime($activity[$platform.'EndTime']);
        if (empty($startTime) || empty($endTime)){
            $startTime = $activity['startTime'];
            $endTime = $activity['endTime'];
        }

        if ($startTime > $reqTime) {
            throw new SzException(90001);
        }
        if ($endTime <= $reqTime) {
            throw new SzException(90002);
        }

         return $activity['type'];
    }
}